How initialize a model only when used (lazy)
cardmaster opened this issue · 1 comments
cardmaster commented
e.g. we had a custom hook needs fetch data from network.
function someModel() {
let [state, setState] = useState({loading:false, valid:false})
useEffect(()=>{
setState({loading:true, valid:false})
axios().then(()=>{
setState({loading:false, valid:true})
})
}, []);
return state;
}
export default createModel(someModel); //the network request will happens here.
The useEffect() will happen when using 'createModel', what should I do If I want the request happens only when I using that model?
e.g.
import useSomeModel ..
function SomeComponent() {
let model = useSomeModel(); //I want the request happens on the first time using this model
}