Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zustand: Get a state from another Zustand store

I have created two Zustand stores in a 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) => ({

});
like image 695
Mir Sisir Avatar asked Feb 01 '26 02:02

Mir Sisir


1 Answers

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

like image 99
aygulh Avatar answered Feb 02 '26 16:02

aygulh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!