From ceb2c60855796a6fdf790809842cc32cbbd47e49 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 9 Nov 2018 09:38:08 -0800 Subject: [PATCH] Updated useReducer reducer example to show default case --- content/docs/hooks-reference.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/content/docs/hooks-reference.md b/content/docs/hooks-reference.md index db93175b..c72c709a 100644 --- a/content/docs/hooks-reference.md +++ b/content/docs/hooks-reference.md @@ -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; } }