TypeError:Cannot read properties of undefined(阅读'clearance')- NextJs

tzdcorbm  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(152)

在我的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>
o3imoua4

o3imoua41#

不知怎么的它起作用了

const clearStorage = (): void => {
    useItemsStore.persist.clearStorage();
}

重新启动NextJs后,等待几秒钟,然后刷新页面.然后重新启动NextJs
希望NextJ下次能跑得更快...

相关问题