react.dev
react.dev copied to clipboard
docs: Add test scenario to exercise in queueing-a-series-of-state-updates.md
I've found a wrong solution through a reduce() operation when solving this exercise as follows:
export function getFinalState(baseState, queue) {
let finalState = queue.reduce((accumulator, currentChange) => {
if ('function' === typeof currentChange) {
return currentChange(accumulator);
} else {
return baseState + currentChange;
}
}, baseState);
return finalState;
}
All tests were passing successfully.
The return statement for queued numbers should've been this instead: return currentChange;
This change introduces a new test case to fail in this case :')
Size changes
📦 Next.js Bundle Analysis for react-dev
This analysis was generated by the Next.js Bundle Analysis action. 🤖
This PR introduced no changes to the JavaScript bundle! 🙌