ITADN

Error for `useStore`: Warning: The result of getSnapshot should be cached to avoid an infinite loop

#22Closedadamtaylor13 创建于 2023-09-13
A
adamtaylor13commented
I'm using nanostores (`0.9.3`), in astro (`1.9.0`) with react (`18.0.0`). I've got this store: ```ts import { DataResponse } from "@components/hooks/useApi"; import { createFetcherStore } from "@stores/apiFetcher"; import { useStore } from "@nanostores/react"; export const $account = createFetcherStore<DataResponse<"/account">>([ "/account", ]); export const useAccount = () => { const fetchResults = useStore($account); // ... return fetchResults; }; ``` Used in a React component like so: ```tsx export default function NavAuthOptions() { const { data: account } = useAccount(); // ... } ``` And I get this error in the console: ![CleanShot 2023-09-13 at 09 51 56@2x](https://github.com/nanostores/react/assets/2922753/d570e766-175e-4505-b014-0aa0d076988a) I should note however that there doesn't actually appear to be any errors. The site seems to function just fine, which may actually be more disconcerting than the error itself! My Google-Fu has failed me here as the only semi-related issue I could find was this https://github.com/pmndrs/zustand/discussions/1936, however it doesn't appear related as I don't have a `.getState()` function. I've also tried just using `useStore($account)` directly inside my component instead of importing `useAccount`, but the error still shows in the console.
关闭于 2024-09-23 14 条评论