Execute a code after change in two states in react using hooks

I have two empty states named stateA and stateB. I made two different api call and changed the the states to the response fetched (array of objects) using setStateA and setStateB accordingly.
Now i want to check if a particular item is present in both the states and if present add that item in a 3rd array and map that array later .

How to do this?

Upvotes: 0

Views: 52

Answers (1)

Evert
Evert

Reputation: 99851


useEffect(() => {

  /* compare here and store in stateC */

}, [stateA, stateB]);

Upvotes: 1

Related Questions