Skip to content

Commit

Permalink
update example more useful
Browse files Browse the repository at this point in the history
  • Loading branch information
jin60641 committed Jan 7, 2024
1 parent 9c38e11 commit 5914037
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,12 @@ counterReducer(0, increment()); // => 1
A default handler can be attached, which is invoked for all actions not associated with a handler.
```ts
const add = createAction('todos/ADD', length => length)<number>();
const reset = createAction('', () => 0)<number>();
const counterReducer = createReducer(0)
.handleAction(add, (state, action) => state + action.payload)
.defaultHandler((state, action) => state = action.payload);

const store = createStore(counterReducer);
store.dispatch(add(3));
store.dispatch(reset());
const rootReducer = combineReducers({ /* ... */ });
type RootState = StateType<typeof rootReducer>;
const signOut = createAction('root/SIGN_OUT');
export default createReducer(undefined as RootState)
.handleAction(signOut, (state, action) => rootReducer(undefined, action))
.defaultHandler((state, action) => rootReducer(state, action))
```
#### Alternative usage with regular switch reducer
Expand Down

0 comments on commit 5914037

Please sign in to comment.