*Zusatand독일어로 상태래..

npm i zustand
Zustan의 create 함수를 사용하여 상태 저장소를 생성
useStore 훅을 통해 저장소에 접근하여 상태를 읽거나 업데이트할 수 있다
// store.js
import { create } from 'zustand';
const useCounterStore = create((set) => ({
count: 0, // 초기 상태
increment: () => set((state) => ({ count: state.count + 1 })), // 상태 업데이트
decrement: () => set((state) => ({ count: state.count - 1 })), // 상태 업데이트
}));
export default useCounterStore;코드를 입력하세요
// App.js
import React from 'react';
import useCounterStore from './store';
const App = () => {
const count = useCounterStore((state) => state.count); // 상태 읽기
const increment = useCounterStore((state) => state.increment); // 액션 호출
const decrement = useCounterStore((state) => state.decrement); // 액션 호출
return (
<div style={{ textAlign: 'center', marginTop: '50px' }}>
<h1>Count: {count}</h1>
<button onClick={increment} style={{ marginRight: '10px' }}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
};
export default App;