'Variable derived from React redux useSelector in useCallback dependency array causes infinite re-rendering
I have a list topics derived from useSelector and I use it in one of my callback function updateXXX and add it into the useCallback array of dependencies, unfortunately it causes infinite rendering. Can someone give me some suggestions? How am I supposed to solve the issue?
const topics = useSelector(...);
const updateXXX = useCallback(() => {
const filteredTopics = topics.filter(...);
}, [topics]);
AFAIK, for useState()
React guarantees that setState function identity is stable and won’t change on re-renders. This is why it’s safe to omit from the useEffect or useCallback dependency list.
My question is do we need to add the return value topics from useSelector() into any dependencies array?
I observed that the infinite rendering happens only when topics is an empty list []
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
