Please enable JavaScript.
Coggle requires JavaScript to display documents.
03. CREATE TRULY REUSABLE COMPONENTS (STATE (React lumberjack, If we pass…
03. CREATE TRULY REUSABLE COMPONENTS
CREATING CLASSES
The createClass factory
getInitialState()
getDefaultProps()
Autobinding
Extending React.Component
The new ES2015 arrow function automatically binds the
current this to the body of the function
The issue is that, if we are passing the function down to a child component, it receives a new prop on each update which leads to inefficient rendering
Stateless functional components
Stateless functional components also receive a second parameter which represents the context
Refs and event handlers
No reference to component
In fact, the shouldComponentUpdate function does not exist, and there is not a way to tell React that a functional component should not be rendered if the props (or a particular prop) are not changed
STATE
React lumberjack
If we pass any function as a second parameter of the setState, it gets fired when the state is updated, and the component has been rendered
Every time we can compute the final value from the props, we should not store any data into the state
We should store into the state only values that we are using inside the render method
Prop types
React Storybook isolates a component so that you can render single components without
running the entire app, which is perfect for both development and testing
React Docgen