How to solve TypeError: arr[Symbol.iterator] is not a function in my React project
The way you're consuming the return values in the IndividualProject
component of your useSelectedProjectValue
custom hook is wrong:
const [projects, setProjects] = useProjectsValue();
should be
const { projects, setProjects } = useProjectsValue();
React uses array destructuring e. g. for their useState
, but your useSelectedProjectValue
hook is rather returning an object and not an array, so you have to consume it in the components with object desctructuring. Or change the return value of the custom hook to an array.
If you want to learn more about this topic I recommend reading Kent C. Dodds' blog: https://kentcdodds.com/blog/react-hooks-array-destructuring-fundamentals