zustand.ts 625 B

123456789101112131415161718192021222324252627282930313233
  1. import { create } from 'zustand';
  2. type State = {
  3. inApp: {};
  4. registration: {
  5. user: {
  6. username: string;
  7. email: string;
  8. password: string;
  9. };
  10. };
  11. };
  12. type Action = {
  13. registration: {
  14. updateRegistrationUserData: (registration: State['registration']['user']) => void;
  15. };
  16. };
  17. const store = create<State & Action>((set) => ({
  18. inApp: {},
  19. registration: {
  20. user: {
  21. username: '',
  22. email: '',
  23. password: ''
  24. },
  25. updateRegistrationUserData: (userData) =>
  26. set((state) => ({ registration: { ...state.registration, user: userData } }))
  27. }
  28. }));
  29. export default store;