如何在typescript中使用subcribe
方法?我收到错误Property 'subscribe' does not exist on type 'BearState'
//store.ts
import { create } from 'zustand'
interface BearState {
bears: number
increase: (by: number) => void
}
export const useBearStore = create<BearState>()((set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}))
//App.tsx
function App() {
const bearStore = useBearStore()
const unsub = bearStore.subscribe(console.log)
return (
<div>
</div>
)
}
export default App
1条答案
按热度按时间a64a0gku1#