Babel给出Uncaught TypeError:无法读取null的属性
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Babel给出Uncaught TypeError:无法读取null的属性相关的知识,希望对你有一定的参考价值。
我遇到了这个错误,我得到了babel:UnCaught TypeError:无法读取null的属性'term'这是因为我将组件的状态传递给播放列表子组件的播放列表道具。
class PlaylistSearchBar extends React.Component{
constuctor(){
super();
const initialState = {
term: {tracks: [], playlists: []}
}
this.state = {
...initialState
};
}
return(
<div>
<div className="main">
<div className="ui massive icon input">
<input type="text" placeholder="Search for a song or artist..." className="js-search input-search"/>
<i className="search icon js-submit"></i>
</div>
<button onclick={localStorageClear()} className="clear">Clear Playlist</button>
</div>
<div className="search-results js-search-results ui cards">
</div>
Error here at term --> <Playlist playlists = {this.state.term.playlists} setTracksToNil = {this.setState({tracks: []})} embedItems = {this.getEmbed}/>
</div>
);
任何帮助,将不胜感激。谢谢。
一些错误,构造函数拼写错误,并且您没有包含渲染功能。
class PlaylistSearchBar extends React.Component {
constructor(props) {
super(props);
const initialState = {
term: { tracks: [], playlists: [] }
}
this.state = {
...initialState
};
}
render() {
return (
<div>
<div className="main">
<div className="ui massive icon input">
<input type="text" placeholder="Search for a song or artist..." className="js-search input-search" />
<i className="search icon js-submit"></i>
</div>
<button onclick={localStorageClear()} className="clear">Clear Playlist</button>
</div>
<div className="search-results js-search-results ui cards">
</div>
<Playlist playlists={this.state.term.playlists} setTracksToNil={this.setState({ tracks: [] })} embedItems={this.getEmbed} />
</div>
);
}
}
以上是关于Babel给出Uncaught TypeError:无法读取null的属性的主要内容,如果未能解决你的问题,请参考以下文章
jQuery UI Autocomplete JSON 给出错误:Uncaught TypeError: Cannot use 'in' operator to search '62' in
vue中引入mui报Uncaught TypeError: 'caller', 'callee', and 'arguments' properties
Webpack Babel 加载错误 - Uncaught SyntaxError: Unexpected token import [重复]
如何修复 babel 反应“Uncaught SyntaxError: Unexpected token <”
Gulp、Vue、Webpack、Babel 和 Uncaught SyntaxError:意外的令牌导入
Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerText') in OpenWetherMa