ReactJS Flashcards
What is a React Element
An object representation of some UI component. It describes what you want to see on screen.
What is a React Component
A function or a class which optionally accepts input and returns a React Element (via JSX).
Encapsulated unit of code which has a function on the frontend.
When would you use a Class Component or a Functional Component?
You use a Class Component if you wish to track state, otherwise you’d use Functional.
What are keys
Keys are what help React keep track of what items have changed, been added, or been removed from a list
What is a Controlled Component?
A component where React (Virtual DOM) is in control of the component, as opposed to the native DOM.
What is an Uncontrolled Component?
A component where data is handled by the native DOM as opposed to letting React (Virtual DOM) be in control.
(accomplished by refs
)
What are refs
refs are an “escape hatch” which allow direct access to the native DOM. It is achieved by adding the “ref” attribute to a component.
ref’s value is a callback function where the underlying DOM element of what React is representing is returned.
this.input = input} />
What are Keys in React?
Keys are essentially unique identifiers for each element that has been changed, added, or removed from a list <li>
What are the different states of the React Lifecycle?
Mounting
Updating
Unmounting
Error Handling
What are the different Lifecycle events offered for Components?
componentWillMount componentDidMount componentWillReceiveProps componentWillUpdate componentDidUpdate shouldComponentUpdate componentWillUnmount render
What are the order of Lifecycle events in the Mounting state?
componentWillMount
render
componentDidMount
What are the order of Lifecycle events in the Updating state?
componentWillReceiveProps shouldComponentUpdate componentWillUpdate render componentDidUpdate
What are the order of Lifecycle events in the Unmounting state
componentWillUnmount
In which lifecycle event do you make AJAX requests and why?
componentDidMount
Guarantee that AJAX doesn’t resolve before the component mounts
Newest React sometimes overcalls componentWillMount, so avoid multiple calls.
Why would you use
React.Children.map(props.children, () => )
instead of props.children.map(() => )
You can’t gauarntee that props.children will be an array, so React gives you React.Children.map as a safeguard.