Closed christian-the-brewer closed 1 year ago
I believe the issue is with how we are updating the state in the useEffect? If I do a cold load of the page, the pieces of state movie and providers are null, but if I simply refresh the component again from VSCode by saving, they load in with data as they should
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
MERN
What's the problem you're trying to solve?
We have our show page that makes two calls to the back end. I am receiving an object from the GetOneMovie call that is {movie, providers}, as well a list of favorites with getFavorites. The issue we have is that if we refresh the page, the page doesnt seem to be getting info for movies unless we comment out all the functions we wrote outside of the use effect and then after we load it, we can uncomment them, save it, and the page updates correctly.
Post any code you think might be relevant (one fenced block per file)
``js import { useState, useEffect } from "react"; import '../../index.css'
import { useParams, useNavigate } from 'react-router-dom'
import { Container, Card, Button } from 'react-bootstrap' import LoadingScreen from '../shared/LoadingScreen' import { getOneMovie } from '../../api/movies.js' import messages from '../shared/AutoDismissAlert/messages' import { getFavorites, addToFavorites, removeFromFavorites } from "../../api/favorites";
//the movie's id comes from the 3rd party API //Hide show movie and favorites behind auth //fill out show movie with deetz
const ShowMovie = (props) => { const [movie, setMovie] = useState(null) const [providers, setProviders] = useState(null) const [favorites, setFavorites] = useState([]) const [areLoggedIn, setareLoggedIn] = useState(true) const [updatedFavorites, setUpdatedFavorites] = useState(false)
}
export default ShowMovie`
141 | //Function to map over genres and create an array of strings 142 | // UNCOMMENT 143 | console.log("movie:", movie)
What is your best guess as to the source of the problem?
I am not sure what the issue could be.
What things have you already tried to solve the problem?
a lot of things all day, haha
Paste a link to your repository here