[英]Cannot find module after using state syntax
I am getting the following error in my browser console:我在浏览器控制台中收到以下错误:
Uncaught Error: Cannot find module "./components/search_bar"
未捕获的错误:找不到模块“./components/search_bar”
I am learning ReactJS and upon working on creating a very simple component, I stumbled upon the above error.我正在学习 ReactJS,在创建一个非常简单的组件时,我偶然发现了上述错误。 It occurred after applying the
state
syntax in my SearchBar
class/component.它发生在我的
SearchBar
类/组件中应用state
语法之后。 I am simply seeking on some enlightenment towards what is wrong, because I am not able to identify this after revising my code.我只是在寻求一些对错误的启发,因为在修改我的代码后我无法识别这一点。
Please reference the below code:请参考以下代码:
import React, {Component} from 'react';
class SearchBar extends Component {
constructor(props){
super(props);
this.state = {term: ""};
}
render(){
return (
<div>
<input onChange={
event => this.setState({
term: event.target.value;
})
}/>
Value of input: {this.state.term}
</div>
);
}
}
export default SearchBar;
import React from 'react';
import ReactDOM from 'react-dom';
import SearchBar from './components/search_bar';
const App = () => {
return (
<div>
<SearchBar />
</div>
);
}
ReactDOM.render(<App />, document.querySelector(".container"));
fix the syntax error, (semicolon).修复语法错误,(分号)。 also assign the value of your state to the input
还将您的状态值分配给输入
<input
onChange={ event => this.setState({term: event.target.value}) }
value={this.state.term}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.