0

I have component which receive some props, I've realized the component renders at unwanted times and cases

So I checked each props explicitly with simple UseEffect hook to find if props are really changed and causes the re-Render.

Indeed, some props is 'changing' when clicking on some buttons, the problem is the props not really changing and even if I put mock data inside the props (propsName={10}), the useEffect hook 'thinks' that the prop is changed.

This is the useEffect hook I've used:

UseEffect(() => {
  console.log(`prop has changed', propName)
}, [propName])

What could be the problem, Why it looks like the props changed even if it's not really changes?

Eylon Shmilovich
  • 354
  • 1
  • 4
  • 11
  • could you provide a bit more detail? I have a guess why that is happening, but without knowing the structure it is hard to answer that. – Michel Engelen May 13 '22 at 13:40

1 Answers1

0

The useEffect will run on first render of the component, and then any time an item in the dependency changes. Check out the React Docs for more info on conditionally firing an effect.