mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
Merge pull request #1386 from reactjs/useReducer-example
Updated useReducer reducer example to show default case
This commit is contained in:
@@ -190,6 +190,10 @@ function reducer(state, action) {
|
||||
return {count: state.count + 1};
|
||||
case 'decrement':
|
||||
return {count: state.count - 1};
|
||||
default:
|
||||
// A reducer must always return a valid state.
|
||||
// Alternatively you can throw an error if an invalid action is dispatched.
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +227,10 @@ function reducer(state, action) {
|
||||
return {count: state.count + 1};
|
||||
case 'decrement':
|
||||
return {count: state.count - 1};
|
||||
default:
|
||||
// A reducer must always return a valid state.
|
||||
// Alternatively you can throw an error if an invalid action is dispatched.
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user