在编译一个简单的React应用程序时,我在文件的最后(空白)行收到一条错误消息,说“意外令牌”
import { Link, Redirect } from "react-router-dom";
import './App.css';
class Companies extends Component {
constructor(props) {
super(props);
var user = null;
if (props.hasOwnProperty("user")){
user = props["user"];
}
this.state = {
user: user,
companies: [],
};
}
}
export Companies
是我正在尝试运行的代码
Failed to compile.
./src/Companies.js
Line 22:1: Parsing error: Unexpected token
20 |
21 | export Companies
> 22 |
| ^
是我收到的错误消息。
答案 0 :(得分:1)
要导出类,正确的语法为:export default Class
尝试一下:
import { Link, Redirect } from "react-router-dom";
import './App.css';
class Companies extends Component {
constructor(props) {
super(props);
var user = null;
if (props.hasOwnProperty("user")){
user = props["user"];
}
this.state = {
user: user,
companies: [],
};
}
}
export default Companies