Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6291

React-Navigation update a header icon from itself

$
0
0

I am trying to update a header icon using itself. I have a heart icon in the headerRight component:

const [enabled, setEnabled] = useState(false);navigation.setOptions({   headerRight: () => (<TouchableOpacity onPress={() => setEnabled(prev => !prev)}>{enabled ? <HeartFill/> : <HeartOutline/>}</TouchableOpacity>)});

But this doesn't work since navigation.setOptions() is never 're-called' to update to the correct icon. How can I make a child update itself in react-navigation?

Instead of setEnabled I could pass navigation.setOptions() again but that would just make me do some endless nesting if I want to toggle between more than 2 states.


Viewing all articles
Browse latest Browse all 6291

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>