importReactfrom"react"import{atom}from"recoil"import{useAtomReducer}from"use-atom-reducer"exportconstcounterState=atom({key: 'counter',// unique ID (with respect to other atoms/selectors)default: 0,// default value (aka initial value)});exportdefaultfunctionCounter(){constreducer=(state,action)=>{if(action.type=="incr"){returnstate+action.payload}if(action.type=="decr"){returnstate-action.payload}}const[count,dispatch]=useAtomReducer(counterState,reducer)consthandleIncr=()=>{dispatch({type:"incr",payload:1})}consthandleDecr=()=>{dispatch({type:"decr",payload:1})}return<div>{count}<buttononClick={handleIncr}> INCREMENT </button><buttononClick={handleDecr}> DECREMENT </button></div>}