React Flashcards
Why use functional components over class based components?
- Less code
- Easier to understand
- Stateless
- Simpler to test
- No ‘this’ binding
- Easier to extract smaller components
Why should we keep our components small?
Small components are easier to: Read Test Maintain Reuse
Why use arrow functions when declaring methods in class based components?
In order to bind the this keyword to the class.
When should we use a function, rather than an object, in this.setState?
When the new state we want to set rely on the previous state.
What can the function we can pass to this.setState() take as arguments?
this.setState((?,?) => {
});
prevState, props
What is prop-types and what is its purpose?
It is an external library for typechecking props
How to use prop-types?
import PropTypes from ‘prop-types’
ComponentName.propTypes = {
name: PropTypes.string.isRequired
}
https://reactjs.org/docs/typechecking-with-proptypes.html