Fundamentals Flashcards
What syntax do you use to render the App component into an HTML element with id “root”?
ReactDOM.render(, document.getElementById(“root”));
What’s a good use case to using a function while rendering a dynamic list of items?
If we need to compute a value based on properties of items in the loop.
What’s the right syntax to assign the function doSomething as the handler of a click event?
onClick={doSomething}
When is it recommended to pass this.setState a function instead of an object
When the new state depends on the old state
We have a boolean X. We want to render component A if X is true, and component B if X is false. Which is correct?
{ X ? <a></a> : <b></b> }
What function can be used to change the state of a React component?
this.setState
What are the 2 objects that act as the input of a Class-based component?
state and props
When is the class component syntax needed?
When we need to manage state or use lifecycle methods
A module in a file myClass.js exports a class like this:
export default MyClass;
How can MyClass be imported in another module?
import My from ‘./myClass’;
What is a good reason to use a state library like Flux or Redux?
Root components get too bloated with maintaining state.
What is a good lifecycle method to use when you want to fetch data from a webservice?
componentDidMount
In the root of a React application there is a folder named `my-component’. It contains an index.js file with a component named ‘MyComponent’ that gets exported as the default. What is the best way to import this component?
import MyComponent from ‘./my-component’;
Why must setState be used to add to the state?
Because doing so triggers the re-rendering of the involved components.
What problem does context solve?
Passing on the same data via props over and over again
What is React’s approach to separation of concerns?
What’s displayed in the browser is only a reflection of the state of the application.