Tyler McGinnis Interview Questions Flashcards
What happens when you call setState?
The first thing React will do when setState is called is merge the object you passed into setState into the current state of the component. This will kick off a process called reconciliation. The end goal of reconciliation is to, in the most efficient way possible, update the UI based on this new state. To do this, React will construct a new tree of React elements (which you can think of as an object representation of your UI). Once it has this tree, in order to figure out how the UI should change in response to the new state, React will diff this new tree against the previous element tree. By doing this, React will then know the exact changes which occurred, and by knowing exactly what changes occurred, will able to minimize its footprint on the UI by only making updates where absolutely necessary.
What’s the difference between an Element and a Component in React?
Simply put, a React element describes what you want to see on the screen. Not so simply put, a React element is an object representation of some UI.
A React component is a function or a class which optionally accepts input and returns a React element (typically via JSX which gets transpiled to a createElement invocation).
When would you use a Class Component over a Functional Component?
If your component has state or a lifecycle method(s), use a Class component. Otherwise, use a Functional component.
What is the Virtual DOM?
A JavaScript representation of the actual DOM.
What is React.Component?
The way to create a new component.
What is the render ( … method …) ?
Describes what the UI will look like for that component. Every component is required to have a render mkethod.
What does ReactDOM.render do?
Renders a React component to a DOM node.
What is ‘state’?
The internal data store (object) of a component.
What is ‘constructor (this.state)’?
The way in which you establish the initial state of a component.
What does ‘setState’ do?
This is a helper method used for updating the state of a
component and re-rendering the UI
What are ‘props’?
The data which is passed to the child component
from the parent component.
What are ‘propTypes’?
Allows you to control the presence, or types of
certain props passed to the child component.
What are ‘defaultProps’?
Allows you to set default props for your component.
What is the Component Lifecycle?
- componentDidMount — Fired after the component is mounted
- componentWillUnmount — Fired before the component will unmount
- getDerivedStateFromProps - Fired when the component mounts and
whenever the props change. Used to update the state of a component when its props change
What are the component events?
- onClick
- onSubmit
- onChange