배열을 arr
을 선언 이러한 세 가지 방법을 고려React ES6에서 세 가지 변수 정의를 사용하는 것이 더 낫습니다. 왜?
// 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];
}
......
}
가장 "올바른"간주 가장 좋은 방법은이 무엇입니까? arr
은 렌더링 할 필요가 없으며 임시 캐시 일뿐입니다.
'변수를 가장 좁은 범위로 제한'은 유용한 제안입니다. –
먼저 고맙습니다. 두 번째로 렌더링 알고리즘이나 차별화 알고리즘이 생깁니 까? 이것은 내가 지금 가지고있는 가장 혼란스러운 곳입니다. – justfine
@sosout 상태를 설정하거나 다시 렌더링하지 않으면 아무 것도 다시 렌더링되지 않습니다. – Li357