19 lines
578 B
JavaScript
19 lines
578 B
JavaScript
import { create } from 'zustand';
|
|
|
|
// 支持函数式更新的 setter 工厂
|
|
const s = (set, key) => (v) =>
|
|
set((state) => ({ [key]: typeof v === 'function' ? v(state[key]) : v }));
|
|
|
|
export const useAuthStore = create((set) => ({
|
|
currentUser: null,
|
|
authChecked: false,
|
|
healthStatus: null,
|
|
healthLoading: false,
|
|
healthError: '',
|
|
setCurrentUser: s(set, 'currentUser'),
|
|
setAuthChecked: s(set, 'authChecked'),
|
|
setHealthStatus: s(set, 'healthStatus'),
|
|
setHealthLoading: s(set, 'healthLoading'),
|
|
setHealthError: s(set, 'healthError'),
|
|
}));
|