MCPcopy Create free account
hub / github.com/streamich/react-use / Demo

Function Demo

stories/createReducer.story.tsx:29–53  ·  view source on GitHub ↗
({ initialCount = 1 })

Source from the content-addressed store, hash-verified

27}
28
29const 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
55storiesOf('State/createReducer', module)
56 .add('Docs', () => <ShowDocs md={require('../docs/createReducer.md')} />)

Callers

nothing calls this directly

Calls 1

addAndResetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…