3

I have been struggling with something that sounds simple. I have been trying to get button when onpressed is called. Have tried several combinators but nothing works. Any ideas?

export default class JobScreen extends React.Component {

    constructor(props) {
        super(props);
    }

    static navigationOptions = ({navigation}) => ({
        title: "Chat with"
    });

    onPressLearnMore(nav) {

        // how do I update the title header 

        console.log("On Pressed" + nav)
    }

    render() {
        const {navigate} = this.props.navigation;


        return (
            <View style={styles.container}>
                <Button
                    onPress={() => {this.onPressLearnMore(navigate)}}
                    title="Learn More"
                    color="#841584"
                />

            </View>
        );
    }
}

1 Answer 1

5

Since the navigationOptions has access to the navigation object, you can set some param on the current screen with this.props.navigation.setParam({ title: ‘some title’ }) and then access it in navigationOptions like this

static navigationOptions = ({ navigation }) => {
  const { state: { params = {} } } = navigation;
  return {
    title: params.title || ‘default title’,
  };
}
Sign up to request clarification or add additional context in comments.

5 Comments

You gotta tell me more for me to help you instead of straight up down voting it lol. Anyway, if you want help, can you provide the error and how are you using the snippet?
I copy pasted the whole block, and it resulted in syntax errors. Was there something I was supposed to modify in it ?
This snippet only works in the context of the original question. So unless you provide how exactly you are using it, it’s hard for me to help you
Even when I take the original code with your snippet and paste it in PHPStorm, I have syntax errors. Right inbetween const and {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.