- 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.jsx
component function with thememo
function imported from Reactmemo
only prevents function executions that are triggered by the parent component, so in this case theApp.jsx
componentmemo
does 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
memo
because checking props withmemo
costs performance
- create a new
ConfigureCounter.jsx
component - define a new
handleSetCount
function inApp.jsx
to pass the information whether the user clicked on the set button from ``ConfigureCounter.jsx` - output the
<ConfigureCounter>
component inApp.jsx
- you could consider removing
memo
fromCounter.jsx
because now it doesn't make much sense anymore
- wrap the
IconButton.jsx
component function with thememo
function - use the
useCallback
hook inCounter.jsx
in conjunction withmemo
to avoid unnecessary re‐executions
- use the
useMemo
hook inCounter.jsx
by wrapping theisPrime
function- 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.jsx
so that you have anid
that does belong to a concrete change object - in
CounterHistory.jsx
, use akey
value that is strictly connected to a specific value to prevent the state from jumping across component instances
- use
useEffect
as a solution for resetting theinitialCount
inCounter.jsx
- use a
key
prop on the<Counter>
component inApp.jsx
instead ofuseEffect
as it's a better way of forcing a component functional reset
- log the
chosenCount
state inside thehandleSetCount
function inApp.jsx
to find out how states are scheduled - try to updated the
chosenCount
like thissetChosenCount(chosenCount + 1);
to see that it will get a strange result - update the
chosenCount
state with the function form where you get theprevChosenCount
to 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