What's the error in the code . Line 51:8: Parsing error: Unexpected token, expected "{"
What's the error in the code . Line 51:8: Parsing error: Unexpected token, expected "{"
我正在学习 reactjs,但在最后一行 export App3 中遇到解析错误;请通过下面的代码人员让我知道错误是什么(代码中的错误是什么。第 51:8 行:解析错误:意外标记,预期为“{”)
import React, { Component } from "react";
import Student from "./Student";
import useCustomHook from "./Customhook";
export default class App extends Component {
constructor(props) {
super(props);
console.log("App - Constructor Called");
console.log(props.name);
this.state = {
roll: "101",
};
}
static getDerivedStateFromProps(props, state) {
console.log("app2");
console.log(props, state);
return null;
}
componentDidMount() {
// you can get data from server and set the data to state
// Ajax is also called in component did mount method
console.log("app - Component did mount working properly");
}
render() {
console.log("app rendered");
return (
<div>
<Student name="Abhishek" />
{/* <h1>Hello</h1> */}
</div>
);
}
}
function App3() {
const data = useCustomHook();
return (
<>
<h1> Hello {data.currState}</h1>
<button type="button" onClick={data.customHandleIncrement}>
Increment
</button>
</>
);
};
export App3;
您必须使用语法 where use export
before function App3()
。
像这样:
export function App3() {
或者您可以使用以下语法:
export { App3 };
我正在学习 reactjs,但在最后一行 export App3 中遇到解析错误;请通过下面的代码人员让我知道错误是什么(代码中的错误是什么。第 51:8 行:解析错误:意外标记,预期为“{”)
import React, { Component } from "react";
import Student from "./Student";
import useCustomHook from "./Customhook";
export default class App extends Component {
constructor(props) {
super(props);
console.log("App - Constructor Called");
console.log(props.name);
this.state = {
roll: "101",
};
}
static getDerivedStateFromProps(props, state) {
console.log("app2");
console.log(props, state);
return null;
}
componentDidMount() {
// you can get data from server and set the data to state
// Ajax is also called in component did mount method
console.log("app - Component did mount working properly");
}
render() {
console.log("app rendered");
return (
<div>
<Student name="Abhishek" />
{/* <h1>Hello</h1> */}
</div>
);
}
}
function App3() {
const data = useCustomHook();
return (
<>
<h1> Hello {data.currState}</h1>
<button type="button" onClick={data.customHandleIncrement}>
Increment
</button>
</>
);
};
export App3;
您必须使用语法 where use export
before function App3()
。
像这样:
export function App3() {
或者您可以使用以下语法:
export { App3 };