我是ReactJS的新手。我试图在render return方法中放置一个条件来显示组件,但遇到了以下错误。
./components/Layouts/Header.js
SyntaxError: /home/user/Desktop/pratap/reactjs/society/society-front/components/Layouts/Header.js: Unexpected keyword 'this' (14:8)
12 | render() {
13 | return (
> 14 | { this.props.custom ? <CustomStyle /> : <DefaultStyle /> }
| ^
15 | );
16 | }
17 | }
以下是我的组件代码 -
import React from "react";
import CustomStyle from "./CustomStyle";
import DefaultStyle from "./DefaultStyle";
class Header extends React.Component {
constructor(props) {
super(props);
this.state = {
custom:this.props.custom
}
}
render() {
return (
{ this.props.custom ? <CustomStyle /> : <DefaultStyle /> }
);
}
}
export default Header;