简体   繁体   English

试图修复我的反应类组件。 收到错误“期望赋值或函数调用,但看到了一个表达式”

[英]Trying to fix my react class component. Getting the error "Expected an assignment or function call and instead saw an expression"

I'm getting the error message:我收到错误消息:

Line 4:2: Expected an assignment or function call and instead saw an expression第 4:2 行:期望赋值或函数调用,但看到的是表达式

I think I wrote this class component the same way I've written them in the past?我想我写这个类组件的方式与我过去编写它们的方式相同? Not sure what I did wrong.不知道我做错了什么。 Any help would be appreciated.任何帮助,将不胜感激。

import React, { Component } from 'react'
import Person from './Components/Person'

class App extends Component {
    state = {
        people: [
            {name: 'David', age: '30'},
            {name: 'Michael', age: '27'},
            {name: 'John' , age: '33'}
        ],
        bool: true
    }

    clickHandler = () => {
        const currentBool = this.state.bool
        this.setState({
            bool: !currentBool
        })
    }

    render () {
        let renderDiv = null
        if (this.state.bool) {
            renderDiv = (
                <div>
                    {this.state.people.map(person => {
                        return <Person name={person.name} age={person.age} />
                    })}
                </div>
            )
        }

        return (
            <div>
                <button onClick={this.clickHandler}>show/hide</button>
                {renderDiv}
            </div>
        )
    }
}

export default App

I think your code looks good.我认为你的代码看起来不错。 You'd see that linting error if you didn't have a return in the statement return <Person name={person.name} age={person.age} /> but since you already have it, it should be good.如果您在return <Person name={person.name} age={person.age} />语句中没有return ,您会看到 linting 错误,但既然您已经有了它,它应该很好。

在此处输入图片说明

But looking at the line number you provided, it doesn't look like that lint error is coming from this file.但是查看您提供的行号,看起来 lint 错误并非来自此文件。 Could that be coming from your Person component?这可能来自您的Person组件吗? You haven't provided the code for it, so just an assumption.你还没有提供它的代码,所以只是一个假设。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获得预期的赋值或函数调用,而是在尝试在 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 制作组件时看到一个表达式 no-unused-expressions - Expected an assignment or function call and instead saw an expression no-unused-expressions when trying to make a component using react 反应错误 [期望赋值或函数调用,而是看到一个表达式] - React error [Expected an assignment or function call and instead saw an expression] 无法渲染我的组件,需要赋值或 function 调用,而是在 React 中看到了一个表达式 - Can't render my component, Expected an assignment or function call and instead saw an expression in React 得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions - getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react 修复 - 预期分配或 function 调用,而是看到一个表达式 - Fix - expected an assignment or function call and instead saw an expression 如何在reactjs中修复“预期的分配或函数调用,而看到一个表达式”? - How to fix “Expected an assignment or function call and instead saw an expression” in reactjs? 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 期望一个赋值或函数调用,而是看到一个表达式做出反应 - expected an assignment or function call and instead saw an expression react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM