在我的 NextJs 组件中,我使用 Zustand persist 在浏览器中进行本地存储。
我使用下面的 Shadcn UI 按钮,但 NextJs 在我的终端中显示以下错误:
components/stateInput.tsx (40:75) @ clearStorage
TypeError: Cannot read properties of undefined (reading 'clearStorage')
<Button className='destructive-color' onClick={useItemsStore.persist.clearStorage}>Clear Storage</Button>
我尝试过使用
const clearStorage = (): void => {
useItemsStore.persist.clearStorage();
}
...
<Button className='destructive-color' onClick={clearStorage}>Clear Storage</Button>
不知怎的,它有效
const clearStorage = (): void => {
useItemsStore.persist.clearStorage();
}
重启NextJs后,等待几秒钟,然后刷新页面...然后可能会再次重启NextJs...
希望NextJs下次能跑得更快......