I am importing an array into "restMovies" and it's working fine - all the data is in place in "restmovies" and is delievered to the rest of the app via the context provider.
However, I need to make changes in the array so I'm trying to copy the "restMovies" array to the "movies" array that will be the array that's being delievered to the rest of the app.
But for some reason I can't "setMovies", the movies array stays empty.
Help?
export const MoviesContext = createContext();
export const MoviesContextProvider = (props) =>
{
const [restMovies, setRestMovies] = useState([]);
const [movies, setMovies] = useState([])
useEffect(() =>
{
axios.get("https://api.tvmaze.com/shows").then(resp => setRestMovies(resp.data));
}, [restMovies.values])
useEffect(() =>
{
restMovies.map(item =>
{
setMovies([...movies, item])
})
}, [movies.values, restMovies.values])
return (
<MoviesContext.Provider value = {[movies]}>
{props.children}
</MoviesContext.Provider>)
}