# Zustand + Immer

By [Suyi](https://paragraph.com/@suyi-cn) · 2022-11-26

---

how to use zustand with immer ?

Code
----

    import create from 'zustand';
    import { produce } from 'immer';
    
    interface AuthState {
      user?: {
        id: number;
        address: string;
        name?: string;
        email?: string;
        avatar?: string;
        token?: string;
        roles?: string[];
      };
    
      updateAuth: (data: AuthState) => void;
      resetAuth: () => void;
    }
    
    export const useUser = create<AuthState>((set, get) => ({
      updateAuth: (data: AuthState) => {
        set(
          produce((draft: AuthState) => {
            draft.user = data.user;
          })
        );
      },
      resetAuth: async () => {
        set(
          produce((draft: AuthState) => {
            draft.user = undefined;
          })
        );
      },
    }));
    
    export default useUser;

---

*Originally published on [Suyi](https://paragraph.com/@suyi-cn/zustand-immer)*
