function init(initialCount) { return {count: initialCount};}function reducer(state, action) { switch (action.type) {
case 'increment':
return {count: state.count + 1};
case 'decrement': return {count: state.count - 1};
case 'reset’
: return init(action.payload);
default
:
throw new Error(); }}function Counter({initialCount}) { const [state, dispatch] = React.useReducer(reducer, initialCount, init); return (<> Count: {state.count}
>);}