I am doing:
const {data} = useSWR("api/data", fetcher, {refreshInterval: 10000})
console.log(data.find(d => d.id === "123"))
However, the error:
TypeError: Cannot read properties of undefined (reading 'find')
May I ask how I can solve it?
I am doing:
const {data} = useSWR("api/data", fetcher, {refreshInterval: 10000})
console.log(data.find(d => d.id === "123"))
However, the error:
TypeError: Cannot read properties of undefined (reading 'find')
May I ask how I can solve it?
2
Answers
Check data before executing
find()
method on it.Try to use
filter()
method on arrayTry this….