this.state within react-navigation screen -
i'm having trouble accessing , defining state. app uses react-navigation. overall within app can work state (without errors), within primary tabbar screens, "null not object" error when use simple definition of state below.
i not using redux
export class review_screen extends react.component { // set title @ top of page static navigationoptions = ({navigation}) => ({ title: navigation.state.params.title }); constructor(props) { super(props); const { params } = this.props.navigation.state; this.state = { // general id info barcode: params.productdata.barcode, userid: params.user.id, username: params.user.name, expanded: false, testing: 'hallo hallo', }; } render() { console.log('-_-_-_-_-_-_-_-_-_-_-_-_-'); console.log(this.state.testing); console.log('-_-_-_-_-_-_-_-_-_-_-_-_-'); const { params } = this.props.navigation.state; etc... // results in error "null not object (evaluating 'this.state.testing')
i assume because supposed work differently state when within react-navigation.
how define local state variables? best practice? @ point go redux, not ready yet.
well, that's embarrassing. issue arose because had react-native on "hot reloading", while coding.
this means asking variable wasn't defined, because constructor wasn't called (the app live while coding).
once restart or reload app, define state (because while loading app calls constructor().
hope serves else..
Comments
Post a Comment