import React , { useReducer } from "react" ; interface State { count : number ; } type Action = { type : "increment" ; } | { type : "decrement" ; } ; const counterReducer = ( state , action ) => { switch ( action . type ) { case "increment" : return { count : state . count + 1 } ; case "decrement" : return { count : state . count - 1 } ; default : throw new Error ( ) ; } } ; const App = ( ) => { const [ state , dispatch ] = useReducer ( counterReducer , { count : 0 } ) ; return ( < > < p > Count : { state . count } < /p> < button onClick = { ( ) => dispatch ( { type : "decrement" } ) } > - < /button> < button onClick = { ( ) => dispatch ( { type : "increment" } ) } > + < /button> < />); } ; export default App ;