H
H
herasko-sg2021-04-03 14:57:44
React
herasko-sg, 2021-04-03 14:57:44

React Redux useEffect?

In useEffect , I call the function, on request to the server:

useEffect(() => {
    dispatch(getMovies());
    dispatch(getTrending());
}, [dispatch]);

The problem is that when this data is received
const {nowPlaying, trendingLoad, trending, nowLoading} = useSelector(state => state.movie);

They are passed to the component twice, with the first and the second time receiving data.
I noticed that this is nerfed by removing one dispatch from the effect. But, and the essence of the question is how to make two different requests when the page is launched?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Setux, 2021-04-03
@Setux

For example, use a thunk in which you write these two dispatches and call only one function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question