From 5475171fdf1e5fc430f970f48e31e3249fcd6ee2 Mon Sep 17 00:00:00 2001 From: Gil Teitelbaum Date: Thu, 17 Sep 2020 16:44:22 +0300 Subject: [PATCH] fix bug with missing parentisis --- src/components/movies.jsx | 10 +++++----- src/movieContext.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/movies.jsx b/src/components/movies.jsx index 62ad22b..ec3d16a 100644 --- a/src/components/movies.jsx +++ b/src/components/movies.jsx @@ -80,16 +80,16 @@ export default function Movies(props) { if (page > 1) { let holdMovies = movies.concat(moviesRetrieved.data.Search); setMovies(holdMovies); - console.log("holdMovies.length=" + holdMovies.length + " " + moviesSearch.movies.length); - setMoviesSearch({ movies: [...holdMovies], totalMovies: moviesRetrieved.data.totalResults, lastPage: page, movieSearchName: movieSearchName, movieYear: movieYear }) + setMoviesSearch(previousMovies => ({ ...previousMovies, movies: [...holdMovies], lastPage: page })); } - else + else { setMovies(moviesRetrieved.data.Search); - setMoviesSearch({ movies: moviesRetrieved.data.Search, totalMovies: moviesRetrieved.data.totalResults, lastPage: page, movieSearchName: movieSearchName, movieYear: movieYear }) + setMoviesSearch({ movies: moviesRetrieved.data.Search, totalMovies: moviesRetrieved.data.totalResults, lastPage: page, movieSearchName: movieSearchName, movieYear: movieYear }) + } } catch (ex) { setIsLoading(false); if (ex.response && ex.response.status === 404) { - alert("not found") + alert("not found"); } } } diff --git a/src/movieContext.js b/src/movieContext.js index a5e3e45..db779fc 100644 --- a/src/movieContext.js +++ b/src/movieContext.js @@ -1,7 +1,7 @@ import React, { createContext, useState } from 'react'; -export const MovieContext = createContext(); +export const MovieContext = createContext([{}, () => {}]); export const MovieProvider = (props) => { const [moviesSearch, setMoviesSearch] = useState({});