- How React Updates The DOM
- Avoiding Unnecessary Updates
- A Closer Look At Keys
- State Scheduling & State Batching
- run
npm install - run
npm run dev - create
README.md
- wrap the
Counter.jsxcomponent function with thememofunction imported from Reactmemoonly prevents function executions that are triggered by the parent component, so in this case theApp.jsxcomponentmemodoes not care about internal changes- But external changes of course only makes sense for this component here to be executed if the prop value changed
- Don't overuse
memobecause checking props withmemocosts performance
- create a new
ConfigureCounter.jsxcomponent - define a new
handleSetCountfunction inApp.jsxto pass the information whether the user clicked on the set button from ``ConfigureCounter.jsx` - output the
<ConfigureCounter>component inApp.jsx - you could consider removing
memofromCounter.jsxbecause now it doesn't make much sense anymore
- wrap the
IconButton.jsxcomponent function with thememofunction - use the
useCallbackhook inCounter.jsxin conjunction withmemoto avoid unnecessary re‐executions
- use the
useMemohook inCounter.jsxby wrapping theisPrimefunction- this hook prevents the execution of normal functions that are called inside of component functions, unless their input changed
- don't overuse
useMemo()
- update
Counter.jsx - output the
<CounterHistory>component inCounter.jsx - change the logic in
Counter.jsxso that you have anidthat does belong to a concrete change object - in
CounterHistory.jsx, use akeyvalue that is strictly connected to a specific value to prevent the state from jumping across component instances
- use
useEffectas a solution for resetting theinitialCountinCounter.jsx - use a
keyprop on the<Counter>component inApp.jsxinstead ofuseEffectas it's a better way of forcing a component functional reset
- log the
chosenCountstate inside thehandleSetCountfunction inApp.jsxto find out how states are scheduled - try to updated the
chosenCountlike thissetChosenCount(chosenCount + 1);to see that it will get a strange result - update the
chosenCountstate with the function form where you get theprevChosenCountto get thenewCount+ 1 - React performs state batching, which simply means that multiple state updates that are triggered from the same function, for example, are batched together and will only lead to one component function execution
- run
npm install million - update
vite.config.js