global 상태관리 라이브러리
interface State1 {
state: number
setState: (newState: number) => void
}
export const useCountStore = create<State1>((set) => ({
state: 0,
setState: (newState) => set({state: newState})
}))
import { useCountStore } from './store.module'
const App = () => {
const { state, setState } = useCountStore()
/* const { state, setState } = useCountStore(
(state) => ({ state: state.state, setState: state.setState }),
shallow
) */
return (
<div>{state}</div>
)
import { useCountStore } from './store.module'
const App = () => {
const [ state, setState ] = useCountStore(state => ([state.state, state,setStete],shallow)
return (
<div>{state}</div>
)