|
3 | 3 |
|
4 | 4 | import * as React from 'react' |
5 | 5 |
|
6 | | -function countReducer(state,newState) { |
7 | | - return newState |
| 6 | +function countReducer(count,step) { |
| 7 | + return count+step |
8 | 8 | } |
9 | 9 |
|
10 | 10 | function Counter({initialCount = 0, step = 1}) { |
11 | | - // 🐨 replace React.useState with React.useReducer. |
12 | | - // 💰 React.useReducer(countReducer, initialCount) |
13 | | - const [count, setCount] = React.useReducer(countReducer, initialCount) |
| 11 | + const [count, changeCount] = React.useReducer(countReducer, initialCount) |
14 | 12 |
|
15 | | - // 💰 you can write the countReducer function so you don't have to make any |
16 | | - // changes to the next two lines of code! Remember: |
17 | | - // The 1st argument is called "state" - the current value of count |
18 | | - // The 2nd argument is called "newState" - the value passed to setCount |
19 | | - const increment = () => setCount(count + step) |
| 13 | + const increment = () => changeCount(step) |
20 | 14 | return <button onClick={increment}>{count}</button> |
21 | 15 | } |
22 | 16 |
|
|
0 commit comments