({ initialCount = 1 })
| 27 | } |
| 28 | |
| 29 | const Demo = ({ initialCount = 1 }) => { |
| 30 | // Action creator to increment count, wait a second and then reset |
| 31 | const addAndReset = React.useCallback(() => { |
| 32 | return (dispatch2) => { |
| 33 | dispatch2({ type: 'increment' }); |
| 34 | |
| 35 | setTimeout(() => { |
| 36 | dispatch2({ type: 'reset', payload: initialCount }); |
| 37 | }, 1000); |
| 38 | }; |
| 39 | }, [initialCount]); |
| 40 | |
| 41 | const [state, dispatch] = useThunkReducer(reducer, initialCount, init); |
| 42 | |
| 43 | return ( |
| 44 | <div> |
| 45 | <pre>{JSON.stringify(state, null, 2)}</pre> |
| 46 | <button onClick={() => dispatch(addAndReset())}>Add and reset</button> |
| 47 | <button onClick={() => dispatch({ type: 'reset', payload: initialCount })}>Reset</button> |
| 48 | <button onClick={() => dispatch({ type: 'increment' })}>+</button> |
| 49 | <button onClick={() => dispatch({ type: 'decrement' })}>-</button> |
| 50 | <p>Open your developer console to see actions logged by middleware</p> |
| 51 | </div> |
| 52 | ); |
| 53 | }; |
| 54 | |
| 55 | storiesOf('State/createReducer', module) |
| 56 | .add('Docs', () => <ShowDocs md={require('../docs/createReducer.md')} />) |
nothing calls this directly
no test coverage detected
searching dependent graphs…