Raz Buchnik
Raz Buchnik

Reputation: 8411

How to handle errors in the useEffect's skip in react hooks?

I have this useEffect hook:

useEffect(() => {
    console.log(1)
  }, [someObject.someProperty.someNestedProperty])

Now lets say that someProperty is undefined.

It will force blank white screen - how to handle this in useEffect hook?

Upvotes: 0

Views: 39

Answers (1)

Alan Yong
Alan Yong

Reputation: 1033

Can you try this ?

useEffect(() => {
  if (someObject?.someProperty?.someNestedProperty) {
    console.log(1)
  }
}, [someObject])

Upvotes: 2

Related Questions