Search code examples
javascriptreact-nativenavigator-ios

onRightButtonPress React Native undefined is not an object NavigatorIOS


Here There

I have a problem with my React Native code, i am new in React programming, so cannot read the errors correct :-(
Hopefully someone can help

export default class NavigationBar extends Component {

_handleNavigationRequest = () => {
    this.refs.nav.push({
        component: Settings,
        title: 'Genius',
        passProps: { myProp: 'genius' },
    });
}



render() {
    return (
        <NavigatorIOS barTintColor='#50C26B' titleTextColor='#fff' tintColor='#fff'
            initialRoute={{
                component: Genius,
                title: 'Happy Genius',
                rightButtonTitle: 'Add',
                onRightButtonPress: () => this._handleNavigationRequest(),
            }}
            style={style.navBarStyle}
        />
    );
  }
}

Got the error: undefined is noch an object (evaluating 'this.refs.nav.push') enter image description here


Solution

  • You forgot the ref parameter in your NavigatorIOS

    render() {
        return (
            <NavigatorIOS ref='nav' 
                barTintColor='#50C26B' titleTextColor='#fff' tintColor='#fff'
                initialRoute={{
                    component: Genius,
                    title: 'Happy Genius',
                    rightButtonTitle: 'Add',
                    onRightButtonPress: () => this._handleNavigationRequest(),
                }}
                style={style.navBarStyle}
            />
        );
      }