Zustand

현용찬·2024년 12월 15일
0

Zustand

Redux와 마찬가지로 상태 관리 라이브러리이다.
Redux에 비해 상태 관리를 간단하고 효율적으로 수행할 수 있다

설치 명령어

npm install zutand

store(상태 모음집)생성

import create from 'zustand';

const useStore = create((set) => ({
  count: 0,
  increase() {
    set((state) => ({ count: state.count + 1 }));
  },
  decrease() {
    set((state) => ({ count: state.count - 1 }));
  },
}));

export default useStore;

활용
해당 store을 사용하고 싶은 컴포넌트에

const {count,increase} =useStore();

로 선언후 사용하기

profile
항상 웃어 봅시다

0개의 댓글