[英]Can't render my component, Expected an assignment or function call and instead saw an expression in React
I written my code following a udemy course.我按照 udemy 课程编写了代码。 I'm unable to render the Layout component's content is there anything I missed or any syntax mistakes that needs to be corrected to sort this out?
我无法呈现 Layout 组件的内容是否有任何我遗漏的内容或任何需要纠正的语法错误来解决这个问题?
const Aux = (props) => {props.children}
export default Aux;
import React,{Component} from 'react'
import Layout from './components/Layout/Layout';
class App extends Component
{
render() {
return (
<div>
<Layout>
<p>Hai.. Is this working ? </p>
</Layout>
</div>
);
}
}
export default App;
import React from 'react';
import Aux from '../../hoc/Auxx';
const layout = (props) =>(
<Aux>
<div>Toolbar,Sidebar,Backdrop</div>
<main>
{props.children}
</main>
</Aux>
);
export default layout;
You problem is that Aux
is a blank component.你的问题是
Aux
是一个空白组件。
When you use the syntax const Aux = (props) => {props.children}
you actually return nothing!当你使用语法
const Aux = (props) => {props.children}
你实际上什么都不返回!
You see, javascript thinks that { }
is the function itself and not return your props.children
.你看, javascript 认为
{ }
是 function 本身,而不是返回你的props.children
。 Just remove the brackets:只需删除括号:
const Aux = (props) => props.children;
I've modified your code as below:我已将您的代码修改如下:
const Aux = (props) => props.children // removed the {} so that it can return the children
export default Aux;
import React,{Component} from 'react'
import Layout from './components/Layout/Layout';
class App extends Component
{
render() {
return (
<div>
<Layout>
<p>Hai.. Is this working ? </p>
</Layout>
</div>
);
}
}
export default App;
import React from 'react';
import Aux from '../../hoc/Auxx';
const Layout = (props) =>( //changed the layout to Layout: it needs to be capitalized
<Aux>
<div>Toolbar,Sidebar,Backdrop</div>
<main>
{props.children}
</main>
</Aux>
);
export default layout;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.