0

i'm making an youtube like page and on the home page i'm trying to make the favorites section and all videos section to re-render after I modify the fav state (a state that contain a array of objects with the data of the videos). The problem is that I'm not being able to make the all videos re-render, only the fav part. I put the skeleton cards on a useEffect and the load videos function and load favorite videos function on another:

 useEffect(() => {
    setLoading(true)
    const timing = setTimeout(() => {
      setLoading(false)
    }, 1000)
    return () => clearTimeout(timing)
  }, [])

  useEffect(() => {
    loadVideos(sort)
    favVideos()
  }, [fav])
const loadVideos = (sort: string) => {
    api.get(`videos?orderBy=${sort}`).then(({ data }) => {
      setVideos(data)
    })
  }

  const favVideos = () => {
    apiAuth.get('videos/favoritos').then(({ data }) => {
      setFav(data)
    })
  }
Dênis
  • 11
  • 7
  • where are setVideos and setFav implemented, look at the top answer for https://stackoverflow.com/questions/53219113/where-can-i-make-api-call-with-hooks-in-react - very close to what you are asking here – Todd Oct 08 '22 at 02:03
  • Hey setVideos and setFav are implemented on the same page, and the api call already happen on the useEffect hook, idk what is going wrong, but thank you for your answer. – Dênis Oct 12 '22 at 22:41

0 Answers0