0

In my React Native 0.59 App.js, 2 props are passed into each component:

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} />)

Since there is {...props} passed in for other props which may be needed for the component, do I have to initialize the component explicitly with constructor and run super(props) like below?

export default class Event extends React.Component {

    constructor(props) {
      super(props);
      this._isMounted = true;
      this.state = {
        activeEvents: [],
        user: this.props.myself,
        token: this.props.token,
      };

    };
     //more code

Or I can go without constructor like below as well:

export default class Event extends React.Component {

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

Without explicit constructor, where is the better place to initialize this._isMounted = true?

1 Answer 1

1

You don't need to have a constructor in place for this case. You can do something like this:

export default class Event extends React.Component {

      state = {
        activeEvents: [],
        user: this.props.myself,
        token: this.props.token,
      }
      _isMounted = false
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.