Javascript TypeError:无法读取属性';搜索字段';空的
TypeError:无法读取null的属性“searchField” App.render TypeError:无法读取null的属性“searchField” 表示编译器在组件中未找到Javascript TypeError:无法读取属性';搜索字段';空的,javascript,reactjs,react-redux,Javascript,Reactjs,React Redux,TypeError:无法读取null的属性“searchField” App.render TypeError:无法读取null的属性“searchField” 表示编译器在组件中未找到状态 您希望从redux检索这些值,因此必须使用 this.props而不是this.state TypeError:无法读取null的属性“searchField” 表示编译器在组件中未找到状态 您希望从redux检索这些值,因此必须使用 this.props而不是this.state正如我所见,您尝试使用的
状态
您希望从redux
检索这些值,因此必须使用
this.props
而不是this.state
TypeError:无法读取null的属性“searchField”
表示编译器在组件中未找到状态
您希望从redux
检索这些值,因此必须使用
this.props
而不是this.state
正如我所见,您尝试使用的所有道具都来自商店(通过MapStateTrops),因此
const { searchField, onSearchChange, robots, isPending } = this.state;
你应该这样做
const { searchField, onSearchChange, robots, isPending } = this.props;
此外,如果在渲染中使用状态,请不要忘记在组件或构造函数中初始化状态:
// if your state doesn't depend on props
class App extends Component {
state = {
isLoading: false
}
....
//if your state depends on props(rare case but sometimes useful)
class App extends Component {
constructor(props) {
super(props);
const {isLoading} = props;
this.state = {
isLoading
}
}
....
如我所见,您尝试使用的所有道具都来自商店(通过mapStateToProps),因此
const { searchField, onSearchChange, robots, isPending } = this.state;
你应该这样做
const { searchField, onSearchChange, robots, isPending } = this.props;
此外,如果在渲染中使用状态,请不要忘记在组件或构造函数中初始化状态:
// if your state doesn't depend on props
class App extends Component {
state = {
isLoading: false
}
....
//if your state depends on props(rare case but sometimes useful)
class App extends Component {
constructor(props) {
super(props);
const {isLoading} = props;
this.state = {
isLoading
}
}
....
你是如何定义
状态的
?这就是发生错误的文件,如果是愚蠢的错误,你会做出新的反应,所以道歉:在()
中附上渲染App.js的函数的返回语句,然后再试一次。有时它会搞得一团糟。Thank fixed似乎它的道具依赖于它,所以我做了这个。道具而不是这个。状态,它工作得很好你是如何定义状态的
?这就是发生错误的文件新的反应,如果是愚蠢的错误,请道歉:将App.js的函数的return
语句附在()
然后再试一次。有时候它会搞得一团糟。谢谢修复了它的道具依赖性,所以我做了这个。道具代替了这个。状态良好