why store not updated in createAsync?
I update store in createAsync, but why it not updated in JSX?
3 Replies
I don't think createAsync can be used like that
Just return your user from createAsync
but I want to know why it not work?
As brenezl said: "never set state inside primivites (createEffect,createAsync,createSignal,createStore,...)". whenever you find yourself doing this: rethink your architecture. Usually the setter should be called in an event handler or check if you misunderstood how to use the docs.
createAsync is executed on the server, setting the stores state at the server, however the store get recreated on the client during hydration with it's initial state.
Just check your browser and cli (server) console logs. And there' aslo some race condition going on. when enabling break1 you'll get inital state, otherwise updated state.
What you could do instead - but again this looks like a anti pattern:
This will show the initial state and then set data after hydration on the client.