D
D
DMITRY Chernenkiy2021-10-27 03:02:53
React
DMITRY Chernenkiy, 2021-10-27 03:02:53

How can useMemo and useEffect be combined?

There is a component that takes a character id, sends a graphQL request to the server asking for character parameters.
The trouble is that the component also has a useState and it is often re-translated due to a state change. GraphQL query is heavy application slows down.
I tried to directly stick a graphQL query into useMemo but it gives an error "Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement". Perhaps due to the fact that at the end there is an if that shows the loader until the answer comes, and the dock directly prohibits requests in useMemo https://ru.reactjs.org/docs/hooks-reference.html#u... The
question is how memoize query results so that they are not sent with each render?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question