Skip to content

Which is better to use three definitions of variables in React ES6? Why? #11839

@xiubug

Description

@xiubug
// One
const arr = [7,8,9]; 
class WatchStore extends Component {
  constructor(props) {
     super(props);
   }
   ......
}

// Two
class WatchStore extends Component {
  constructor(props) {
     super(props);
     this.state = {
       arr: [7,8,9],
     }
   }
   ......
}

// Three
class WatchStore extends Component {
  constructor(props) {
     super(props);
   }
   componentDidMount() {
     this.arr = [7,8,9]; 
   }
   ......
}

which is the best way to use the three defined methods?
The arr does not need to be rendered, just make a temporary cache comparison new data use!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions