Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React navigation 5.0 header button

Tags:

react-native

I trying to add right navigation header button directly on from Component, and implementation steps have been changed navigation 5.0 version, there is one method that provide add button with method

function HomeScreen({ navigation }) {
  const [count, setCount] = React.useState(0);

  navigation.setOptions({
    headerRight: () => (
      <Button onPress={() => setCount(c => c + 1)} title="Update count" />
    ),
  });

  return <Text>Count: {count}</Text>;
}

but need to implement on it

export default class HomeScreen extends Component {


    constructor() {
        super()

    }
    render() {
        return ()
     }
}
like image 923
Gaurang vyas Avatar asked Jun 19 '26 15:06

Gaurang vyas


1 Answers

You can do this in your component constructor

this.props.navigation.setOptions({
    headerRight: () => <Button />
});
like image 66
1009TN Avatar answered Jun 21 '26 12:06

1009TN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!