在react-native中评估道具时,undefined不是对象

维克拉姆·塞尼(Vikram Saini)

所以我将一些数据传递给我在点击事件上导航的页面

render(){
     const goToPageTwo = () => Actions.gray({text:"hello"});
return(
    </View>
    <Button onPress={goToPageTwo} title="Checkout" color="#841584"/>
      </View>
);
}

现在在我的其他组件中,如果我将其作为道具访问

this.props.text

它给出了一个例外,说道具是不确定的

请指导如何解决谢谢!

更新:

正在访问this.props的代码

   import React, { Component } from 'react';
import { Actions } from 'react-native-router-flux'; // New code
import {
  StyleSheet,
  Text,
  Alert,
  View
} from 'react-native';

const GrayScreen = () => {


  return (
      <View style={styles.container}>
      <Text style={styles.welcome} onPress={() => Actions.black()}>{this.props.text}</Text>
    </View>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'gray',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
    color: 'blue',
  },
});

export default GrayScreen;

路由组件代码

import React, { Component } from 'react';
import { Button } from 'react-native';
import Archives from './components/Archives.js';
import ScarletScreen from './components/ScarletScreen.js';
import GrayScreen from './components/GrayScreen.js';
import Zaika from './components/Zaika.js';

    import {Table, TableWrapper, Row, Rows, Col, Cols, Cell } from 'react-native-table-component';
    import {
       Alert,Platform,
      StyleSheet,
      Text,
      View,TextInput,Keyboard
    } from 'react-native';
    import NavBar, { NavGroup, NavButton, NavButtonText, NavTitle } from 'react-native-nav';
    import { Router, Scene } from 'react-native-router-flux';
    import App1 from './App1.js';


    const instructions = Platform.select({
      ios: 'Press Cmd+R to reload,\n' +
        'Cmd+D or shake for dev menu',
      android: 'Double tap R on your keyboard to reload,\n' +
        'Shake or press menu button for dev menu',
    });

    export default class App extends Component<{}> {



      render() {



        return (

             <Router>
          <Scene key="root">
                  <Scene
          key="zaika"
              component={Zaika}
              title="Delhi zaika"
              initial
            />
                 <Scene key="app1"
              component={App1}
              title="app1"

            />
            <Scene key="scarlet"
              component={ScarletScreen}
              title="Scarlet"

            />
            <Scene {...this.props}  
              key="gray"
              component={GrayScreen}
              title="Gray"

            />

          </Scene>


        </Router>


        );
      }
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
      },
        head: { height: 40, backgroundColor: '#f1f8ff' },
      text: { marginLeft: 5 },
      row: { height: 30 }
    });

你不会有实例的属性props阵营无国籍功能组件

props会通过在作为,而不是第一个参数:

const GrayScreen = (props) => {    
  return (
      <View style={styles.container}>
      <Text style={styles.welcome} onPress={() => Actions.black()}>{props.text}</Text>
    </View>
  )
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React native, undefined 不是对象(评估....)

React Native Undefined 不是对象(评估“this.state.input”)

React Native TypeError:undefined 不是对象(评估“props.getItem”)

react-native undefined不是对象(评估RCCManager.setRootController)

undefined不是对象(评估“ allRowsIDs.length”)(React-Native)

React-Native:undefined 不是对象(评估 'Sn[e]')

React-Native:undefined不是对象(评估'this.props = props')

React Native:undefined 不是对象(评估“props.navigation.navigate”)

TypeError:undefined不是React Native中的一个对象(评估'this.state.Gas')

TypeError:undefined不是React Native中的一个对象(评估'this.state.Gase')

TypeError:undefined不是在react-native-google-places-autocomplete中的对象(评估“ navigator.geolocation.getCurrentPosition”)

如何解决TypeError:undefined不是React-Native中的对象(评估'_core.pathUtils.urlToPathAndParams')

TypeError:undefined 不是 React Native 中的对象(正在评估“addTodo(title, description).then”)

从react-native-static-server启动StaticServer时发生错误:undefined不是对象(评估'this.staticServer.start')

对象不是React Native中的函数(评估'concreteComponentProvider()')

react-native:undefined中的抽屉导航错误不是一个对象(评估'_this.props.navigation.openDrawer()')

React native Undefined不是对象(评估'_react3.default.PropType.shape')

React native Undefined 不是对象(评估'_react3.default.PropType.shape')?

React Native:'undefined 不是一个对象(评估'_react3.PropTypes.bool')

未处理的承诺拒绝:TypeError:undefined 不是评估“departureloc.map”的函数,当在 React Native 中映射 setState 时发生

React Native:undefined 不是一个对象(评估'_this2.props.navigation.navigate')

React Native:TypeError:undefined不是一个对象(评估'_this.props.data.map')

react-native: undefined 不是带有反应导航的对象(评估“_this2.props.navigation”)

React Native:未处理的Promise拒绝:TypeError:undefined不是对象(评估'response.json')

TypeError:undefined不是一个对象(正在评估“ navigation.push”)React Native

undefined不是对象(评估'_this2.props.navigation.navigate')-React Native

React Native:TypeError:undefined不是一个对象(评估'this.props.navigation.navigate')

React Native undefined不是一个对象(评估“ Mapbox.GL.UserTrackingModes”)

React Native TypeError:undefined 不是一个对象(评估'_ref.item')