Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs RN:构造函数与无构造函数,组件有道具_Reactjs_React Native - Fatal编程技术网

Reactjs RN:构造函数与无构造函数,组件有道具

Reactjs RN:构造函数与无构造函数,组件有道具,reactjs,react-native,Reactjs,React Native,在我的React Native 0.59App.js中,向每个组件传递了两个道具: const data = this.props.navigation.state.params.data; const EventWithSelf = (props) => (<Event {...props} myself={data.myself} token={data.result} />) const NeweventWithSelf = (props) => (<NewE

在我的
React Native 0.59
App.js
中,向每个组件传递了两个道具:

const data = this.props.navigation.state.params.data;
const EventWithSelf = (props) => (<Event {...props} myself={data.myself} token={data.result} />)
const NeweventWithSelf = (props) => (<NewEvent {...props} myself={data.myself} token={data.result} />)
或者我也可以不使用构造函数,如下所示:

export default class Event extends React.Component {

      state = {
        activeEvents: [],
        user: this.props.myself,
        token: this.props.token,
      };
      //more code.........  

在没有显式构造函数的情况下,在何处初始化
此项更好。_isMounted=true

对于这种情况,您不需要有
构造函数。您可以这样做:

export default class Event extends React.Component {

      state = {
        activeEvents: [],
        user: this.props.myself,
        token: this.props.token,
      }
      _isMounted = false
}
export default class Event extends React.Component {

      state = {
        activeEvents: [],
        user: this.props.myself,
        token: this.props.token,
      }
      _isMounted = false
}