Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useUpdateInfo 사용방법 #38

Open
tkv00 opened this issue Jul 28, 2024 · 0 comments
Open

useUpdateInfo 사용방법 #38

tkv00 opened this issue Jul 28, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@tkv00
Copy link
Contributor

tkv00 commented Jul 28, 2024

구현내용

  • 유저가 로그인 할 때 자동으로 Zustand저장소에 userId,email이 저장됩니다.
  • 다른페이지에서 필요 시 저장소에서 로그인한 유저의 userId를 통해 검색등 사용가능합니다.
import { create } from "zustand";
import { persist } from 'zustand/middleware'
//유저정보 
export const useUserInfo = create(
    persist(
        (set) => ({
            user: {
              email: null,
              userId: 0,
            },
            setUser: (user) => set({ user }),
          }),
          {
            name:"user-info",
            getStorage:()=>localStorage,
          }
    )
)

사용방법

import { useUserInfo } from "../store/useUserInfo.js";

const user = useUserInfo((state) => state.user);
console.log(user.email);//유저의 이메일
console.log(user.userId);//유저의 고유id
  • 로컬스토리지에 저장
    스크린샷 2024-07-29 03 15 30
@tkv00 tkv00 added the documentation Improvements or additions to documentation label Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant