importReactfrom'react'import{useStateEvents,useReducerEvents}from'metasnippets/hooks/'functionMyComponent(){const[state,dispatch]=useReducerEvents(reducer,initialState)const[test,setTest]=useStateEvents(false)React.useEffect(()=>{document.addEventListener('demo_key',(e)=>{console.log(e.detail)dispatch({...})// or setTest(true)})},[])return(<div/>)}
useHotkeys
import{useHotkeys}from'metasnippets/hooks/'functionMyComponent(){const[amount,setAmount]=useState(0)useHotkeys('ctrl+a',()=>setAmount(prevAmount=>prevAmount+100))useHotkeys('ctrl+d',()=>setAmount(prevAmount=>prevAmount-100))useHotkeys('ctrl+t',(e,ke)=>{if(!e.repeat){console.log(e.repeat);return;}setAmount(prevAmount=>prevAmount-100)},[c])return(<div>{amount>=0 ? 'Add' : 'Remove'}{Math.abs(amount)} dollars{' '}{amount>=0 ? 'from' : 'to'} my bank account.
</div>)}
useSound
import{useSound}from'metasnippets/hooks/'functionMyComponent(){constsound=useSound('http://.../sound.mp3');// sound.play()// sound.stop()return(<div><buttononClick={()=>sound.play()}>
Play sound
</button></div>);}
import{useUnload}from'metasnippets/hooks/'functionMyComponent(){useUnload(e=>{e.preventDefault();e.returnValue='';});return(<div>
Some content
</div>);}