0

I am trying to use setParams to pass a function to handle a button click in my navigationOptions but my app freezes instead. Here is my code and any help would be greatly appreciated. Thanks

const handleVisibility = useCallback(()=>{
         setMenuVisible(!menuVisible)
 },[menuVisible])

 useEffect(()=>{
   props.navigation.setParams({
      visibility:handleVisibility
   })
 },[handleVisibility])
Waheed Akhtar
  • 3,110
  • 1
  • 16
  • 30
Babou
  • 151
  • 1
  • 12

1 Answers1

0

You are setting a param with a function:

props.navigation.setParams({
    visibility:handleVisibility // <-- handleVisibility is a function
})

I think it should be:

props.navigation.setParams({
    visibility:menuVisible // <-- menuVisible insted
})
CevaComic
  • 2,056
  • 2
  • 6
  • 12
  • I am passing the function because in my navigationOptions I have a button and for the onPress of that button I am trying to trigger a function that changes the state that is why I am not passing the value but the function as a workaround – Babou Jun 18 '20 at 20:27
  • Well, try not doing a "workaround", i'm sure there is a good method of doing what you want. – CevaComic Jun 18 '20 at 20:31
  • Thanks for the help. I tried different ways but so far I have found a good one. – Babou Jun 18 '20 at 20:37