reactjsstorestate-managementreact-state-managementzustand

Zustand get state from another Zustand store


*I have created 2 Zustand stores in react application, one is called UserStore, and the other is called SettingsStore, how can I get the state from UserStore to SettingsStore? *

import create from 'zustand';

const UserStore = (set, get) => ({

user: {},

});

I want to use this "user" variable to my other store called SettingsStore

import create from 'zustand';

const SettingsStore = (set, get) => ({



});

Solution

  • You must import UserStore in SettingStore file, and then use UserStore.getState().user