You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change deep state values directly using useAsyncDeepState hook
Using useAsyncDeepState hook you can mutate internal state values directly in the following way (Live Demo):
importReact,{useEffect}from"react";import{useAsyncDeepState}from"use-async-effect2";functionTestComponent(){const[state,setState]=useAsyncDeepState({items: []});useEffect(()=>{console.log(`state has been changed (${JSON.stringify(state)})`);},[state]);constaddItem=async()=>{state.items.push({name: "Mad Max",age: 35,added: Date.now()});setState(true);// we changed the state, so let's notify React about it};return(<divclassName="component"><divclassName="caption">useAsyncDeepState demo</div><ul>{state.items.map((item,index)=>(<likey={index}>{JSON.stringify(item,null,2)}</li>))}</ul><buttononClick={()=>addItem()}>Add item</button></div>);}