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
in the react-model v4, we usually write it like this
exportconst{ useStore }=createStore(()=>{const[todoItems,setTodoItems]=useModel<string[]>([])const[saving,setSaving]=useModel<boolean>(false)constaddItems=useCallback((item)=>setTodoItems(todoItems=>todoItems.push(item)),[])// it will register repeatedly// so may be provide a new store effect hook just execute onceuseEffect(()=>{setSaving(true);awaittodosService.save(todoItems);setSaving(false);},[todoItems])return{
todoItems,
saving,
addItems
}})
The text was updated successfully, but these errors were encountered:
@EzrealPrince It works for me. But I don't think it's the right way for solving this problem.
import{useModel,createStore}from'react-model'importaxiosfrom'axios'letneedRequest=trueconstuseStore=()=>{const[options,setOptions]=useModel({})if(needRequest){axios(url,{data: {}}).then((data)=>setOptions(data))}needRequest=falsereturnoptions}// Model Registerexportconst{useStore: useOptions}=createStore(useStore)
Sometimes we want to watch a store state and do some effects
like this, by easy-peasy https://easy-peasy.vercel.app/docs/api/effect-on.html
in the react-model v4, we usually write it like this
The text was updated successfully, but these errors were encountered: