// This is the store for Page1
const usePageModel1 = create(set => {
result: null,
loading: false,
error: null,
fetchData1: async (id)=> {
try {
set({ loading: true })
const result = await (await fetch(`/api1/${id}`)).json() // load data from api1
set({ loading: false, result })
} catch(error) {
set({ loading: false, error })
}
},
});
const Page1 = () => {
const model = usePageModel1();
// ...
}