TypeError:无法读取未定义的属性(读取“clearStorage”)-NextJs

问题描述 投票:0回答:1

在我的 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>
next.js local-storage zustand
1个回答
0
投票

不知怎的,它有效

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

重启NextJs后,等待几秒钟,然后刷新页面...然后可能会再次重启NextJs...

希望NextJs下次能跑得更快......

© www.soinside.com 2019 - 2024. All rights reserved.