undefined is not an object (evaluating 'this.props.navigator.push')
I'm trying to open a second view with a button but I'm receiving: undefined is not an object (evaluating 'this.props.navigator.push') error.
var RegisterNowButton = React.createClass({
render: function() {
return (
<View>
<TouchableHighlight onPress={this.props.onSelect}>
<View style={styles.registerNowButtonContainer}>
<Text style={styles.registerNowButton}>Sign Up Now</Text>
</View>
</TouchableHighlight>
</View>
);
}
});
var RegistrationScreen = require('./RegistrationScreen');
var LoginOverlay = React.createClass({
registerNow: function() {
this.props.navigator.push({
title: "hey",
component: RegistrationScreen,
});
},
render() {
return (
<View style={styles.buttonsContainer}>
< RegisterNowButton
onSelect={() => registerNow()}
/>
</View>
);
}
});
Crash log:
RCTJSLog> "Error:
stack:
registerNow index.ios.bundle:38452
<unknown> index.ios.bundle:38465
touchableHandlePress index.ios.bundle:32219
_performSideEffectsForTransition index.ios.bundle:30516
_receiveSignal index.ios.bundle:30440
touchableHandleResponderRelease index.ios.bundle:30244
executeDispatch index.ios.bundle:12306
forEachEventDispatch index.ios.bundle:12294
executeDispatchesInOrder index.ios.bundle:12315
executeDispatchesAndRelease index.ios.bundle:11694
forEachAccumulated index.ios.bundle:12571
processEventQueue index.ios.bundle:11901
runEventQueueInBatch index.ios.bundle:17989
handleTopLevel index.ios.bundle:18015
_receiveRootNodeIDEvent index.ios.bundle:17877
receiveTouches index.ios.bundle:17961
jsCall index.ios.bundle:7158
_callFunction index.ios.bundle:7405
applyWithGuard index.ios.bundle:877
guardReturn index.ios.bundle:7207
callFunctionReturnFlushedQueue index.ios.bundle:7414
URL: http://localhost:8081/index.ios.bundle
line: 38452
message: undefined is not an object (evaluating 'this.props.navigator.push')"
Now its work, my example code is following :
var RenderNavBar = React.createClass({ getDefaultProps() { return{ navigator: NavigationExperimental.Navigator }; }, render() { return (
..................... ); }, popToHome(){ this.props.navigator.pop() },
Then, when you want use this RenderNavBar, you use as < RenderNavBar />, after run is not work, its say : this.props.navigator.pop() is not a function.
So the important is: < RenderNavBar navigator={this.props.navigator} />
// The problem of : this.props.navigator.push is not a function. The way is same.
Now, its working, happyyyyy ;)