Notes from reading: https://facebook.github.io/react/docs/thinking-in-react.html
Big idea implementation:
-
Break UI into component hierarchy
- Child components should be children in hierarchies
-
Build a static version
- No interactivity
- Don't use state at all!
-Build bottom-up or top-down
- Simpler? top-down
- Larger? bottom-up, write tests as you build
-
Identify Minimal (but complete) Representation of UI State
- DRY: Don't repeat yourself - It's NOT state if: - passed in from a parent via props - remains unchanged over time - can compute it based on any other state or props in your component
-
Identify where your state should live
- Identify which component *mutates* or owns this state - Highest common owner should hold the state - Can't identify? Make a new component simply for holding the state
-
Add Inverse Data Flow
- components should only update their own state - Example: search for products, filteredProducts changes as searchBar input changes
"When using ES6 classes, React does not automatically bind the member functions inside the component." Source: https://daveceddia.com/avoid-bind-when-passing-props/
handleClick = () => {
OR
constructor(props) {
super(props);
handleClick() {
https://facebook.github.io/react/docs/state-and-lifecycle.html