Open EzrealPrince opened 2 years ago
any update?
@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'
import axios from 'axios'
let needRequest = true
const useStore = () => {
const [options, setOptions] = useModel({})
if (needRequest) {
axios(url, { data: {} }).then((data) =>
setOptions(data)
)
}
needRequest = false
return options
}
// Model Register
export const { useStore: useOptions } = createStore(useStore)
Looking forward to @ArrayZoneYour 's reply ^_^
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