为什么我在ReactJS中将'props'作为参数传递,当我使用ReduxJS时它不会发生?
例如:
React app:
constructor(props){
super(props);
this.state = {
memeLimit: 10
}
}
Redux app:
constructor(){
super();
this.state = {
memeLimit: 10
}
}
谢谢
答案 0 :(得分:3)
使用super(props);
的原因是能够在构造函数中使用this.props
,否则您不需要super(props);
例如
constructor(props){
super(props);
this.state = {
memeLimit: this.props.memeLimit // Here you can use this.props
}
}
这相当于
constructor(props){
super();
this.state = {
memeLimit: props.memeLimit // Here you cannot use this.props
}
}
这与Redux Vs React
无关您可以查看此详细信息:What's the difference between "super()" and "super(props)" in React when using es6 classes?