3 ms·
> It is not obvious that your component re-renders on state updates. I... isn't it? Isn't this like the first thing in the hooks introductory material? If you
by ajkjk 4y ago
> It is not obvious that your component re-renders on state updates.
I... isn't it? Isn't this like the first thing in the hooks introductory material? If you don't find this, yeah, hooks are gonna be a bad time.
- nitwit005 4y agoI went and checked, and it is a bit buried at the bottom of the useState explanation when explaining what an example does: > Line 9: When the user clicks, we call setCount with a new value. React will then re-render the Example component, passing the new count value to it. https://reactjs.org/docs/hooks-state.html https://reactjs.org/docs/hooks-state.html I think they assume you'll figure out that it must do so to function at all.
- bobthepanda 4y agoThis has been true even in the old class components. A component always updates when props update.
- throwaway290 4y agoIt's about state not props. But yes state is more or less implicit props.
- Izkata 4y agoI had a co-worker that assumed it worked template-style, where the value in the JSX would update and what's on the page would re-render, but the component function wouldn't be re-run.