pmndrs / zustand

🐻 Bear necessities for state management in React

Home Page:https://zustand-demo.pmnd.rs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

during the delay it does not change the state, it waits until the requests are all finished, then it returns

Musho-T opened this issue · comments

Summary

package version:

"next": "13.2.1",
"react": "18.2.0",
"zustand": "4.4.1",
"react-dom": "18.2.0",

const useStore = create((set, get) => ({
todos: [],
loading: false,
error: null,
fetchTodos: async () => {
set({ loading: true })
try {
const response = await fetch(SERVER_URI)
if (!response.ok) throw response
set({ todos: await response.json() })
} catch (e) {
let error = e
// custom error
if (e.status === 400) {
error = await e.json()
}
set({ error })
} finally {
set({ loading: false })
}
}
}))

after going to the page through the spa the state { loading: true } does not change and immediately shows { loading: false }
actions is called in getInitialProps (to the server)