jeudi 7 janvier 2021

Nested ternery conditional not woring in useEffect hook

I am trying to have a nested ternary conditional in a useEffect hook in ReactJS. I have done this before with no problem outside of a useEffect hook, but for some reason it doesn't work here.

My working code looks like this:

 useEffect(() => {
    if (myState != '') {
      checkbox ? (
        trueFunction()
      ) : (
        falseFunction
        )
    }
  }, [x]);

This works as expected. When i try to do this with ternary operators it doesn't execute any of my functions inside.

 useEffect(() => {
    myState != '' ?? (
      checkbox ? (
        trueFunction()
      ) : (
        falseFunction
        )
    )
  }, [x]);

Aucun commentaire:

Enregistrer un commentaire