React Hook – useReducer

import React, {usereducer} from 'react'

const initialstate = 0;
const reducer = (state, action)=>{
  switch(action.type){
    case 'increment':
    return{
       state+1
    }
    case: 'decrement':
    retutn{
       state-1
    }
  }
}

const MyComponent = ()=>{
    const [state, dispatch] = useReducer(reducer, initialState);
    return(
       <>
         {state}
         <button onClick{()=> dispatch({type:'increment'})}>
              increment
         </button>
       </>
    )
}

Leave a Reply

Your email address will not be published.