简体   繁体   中英

React navigation custom header

Im trying to use react-navigation custom header like this

static navigationOptions = {
    header: <EventHeader
        subscribestatus={this.props.navigation.getParam('status')}
        confirmation={this.props.navigation.getParam('confirmation')}
        deleteSubscribe={this.deleteSubscribe}
        joinEvent={this.joinEvent}
        onPress={()=>this.props.navigation.goBack()}
        eventname={this.props.navigation.getParam('title')}
    />
};

This header getting params previous screen as you see but im getting undefined is not an object (evaluating 'this.props.navigation')

What i am doing wrong and how can i solve this ?

I hope you found the solution, but for other people which could come here :

navigationOptions can be a function which will pass navigator as first argument and can return an object. So you could write it like so :

static navigationOptions = (navigator) => { return { header: ( <EventHeader subscribestatus={navigator.navigation.getParam('status')} confirmation={navigator.navigation.getParam('confirmation')} //deleteSubscribe={this.deleteSubscribe} //joinEvent={this.joinEvent} onPress={()=>navigator.navigation.goBack()} eventname={navigator.navigation.getParam('title')} /> ) } } Unfortunately, you will not have access to this.deleteSubscribe or this.joinEvent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM