简体   繁体   English

无法渲染我的组件,需要赋值或 function 调用,而是在 React 中看到了一个表达式

[英]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.

相关问题 试图修复我的反应类组件。 收到错误“期望赋值或函数调用,但看到了一个表达式” - Trying to fix my react class component. Getting the error "Expected an assignment or function call and instead saw an expression" 获得预期的赋值或函数调用,而是在尝试在 React 中呈现组件时看到表达式 no-unused-expressions 错误 - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions error when trying to render a component in React 反应问题 - 预期分配或 function 调用,而是看到一个表达式 - React issue - Expected an assignment or function call and instead saw an expression 2022 React - 期望一个赋值或 function 调用,而是看到一个表达式 - 2022 React - Expected an assignment or function call and instead saw an expression React 期望一个赋值或函数调用,而是看到一个表达式 - React Expected an assignment or function call and instead saw an expression 期望一个赋值或函数调用,而是看到一个表达式反应路由器 - Expected an assignment or function call and instead saw an expression react router 反应错误 [期望赋值或函数调用,而是看到一个表达式] - React error [Expected an assignment or function call and instead saw an expression] 期望一个赋值或函数调用,而是看到一个表达式做出反应 - expected an assignment or function call and instead saw an expression react 期望分配或 function 调用,而是看到表达式 React JS - Expected an assignment or function call and instead saw an expression React JS React:需要一个赋值或函数调用,而是看到一个表达式 - React : Expected an assignment or function call and instead saw an expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM