TypeError: Cannot read properties of undefined (reading 'bind')
See original GitHub issueBug report
Description / Observed Behavior
When using the useSWR hook like intended, I originally had no problems with it. However, I discovered today that it suddenly threw the error TypeError: Cannot read properties of undefined (reading 'bind').
This error originates from swr/dist/index.mjs at line 153.
Update
This error only occurred to me when @mux/mux-video-react was installed.
Expected Behavior
useSWR runs like normal, and returns my data.
Repro Steps / Code Example
Implemented useSWR in a custom hook called useQuery, which fetches a query from a sanity.io project through a next API. On the server, this query is cached, ensuring as few API calls to Sanity as possible.
import { useRouter } from 'next/router';
import useSWR from 'swr';
import axios from 'axios';
export default function useQuery<T>(query: string, condition?: boolean) {
// Data from Sanity gets directly linked to the current path in order to revalidate pages that use it
const router = useRouter();
const { data } = useSWR<T>(condition !== false? query:null, async () => {
const res = await axios.get(`/api/query/${query}?path=${router.asPath}`);
return res.data;
}
return data;
}
Additional Context
SWR version - 1.3.0 Axios version - 0.27.2 Next version - 12.2.4 React version - 18.2.0
Until this issue is resolved, I will either prevent usage of SWR in my code, or create my own way of caching the data.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Related StackOverflow Question
@joaisa17 I posted an issue for mux here: https://github.com/muxinc/elements/issues/342
Update: For whatever reason, this error only appears for me when I install @mux/mux-player-react or @mux/mux-video-react packages via yarn alongside SWR.
If I remove those packages, my Next.js app builds successfully.
Bummed, as I can’t seem to figure out how this has any relation to SWR being used in other components.