为什么我得到Erroe:需要一个赋值或函数调用,而是看到一个表达式no-unused-expressions

时间:2019-02-23 03:47:08

标签: reactjs

class Tweet extends React.Component{
    render(){
        return(
            <div className="tweet">
                <ShowTweet linkAvatar={this.props.link} name={this.props.name} userName={this.props.username} tweetText={this.props.content}/>
                <TweetAction />
                <Stats />
            </div>
        );
    }
}

class TweetContainer extends React.Component{
    constructor(props){
        super(props);
    }

    render(){

        const data =  [{name: 'Vuong xuan',username:'vuggg',content:'the good food'},
            {name: 'Jon tathoo',username:'tatoo',content:'the good food'}];

        let numberTweet = data.map(number=>{
            <Tweet linkAvatar={'/image/jennyshen.jpg'} name={number.name} userName={number.username} 
            tweetText={number.content} />
        });

        return(
            <div id="main">
                <h2>Tweet</h2>
                <div id="stream">
                    {numberTweet}
                </div>
            </div>
        );

我正在尝试显示推文,运行时出现错误

./ src / App.js   第180行:需要执行赋值或函数调用,而是看到了一个表达式no-unused-expressions

搜索关键字以详细了解每个错误。

第180行:

            tweetText={number.content} />

1 个答案:

答案 0 :(得分:1)

您在data.map()中缺少返回关键字。看下面:

class TweetContainer extends React.Component{
constructor(props){
    super(props);
}

render(){

    const data =  [{name: 'Vuong xuan',username:'vuggg',content:'the good food'},
        {name: 'Jon tathoo',username:'tatoo',content:'the good food'}];

    let numberTweet = data.map((number, index) => {
        return(
          <Tweet key={'Key-'+ index} linkAvatar={'/image/jennyshen.jpg'} name={number.name} userName={number.username} 
        tweetText={number.content} />
         )
        })

    return(
        <div id="main">
            <h2>Tweet</h2>
            <div id="stream">
                {numberTweet}
            </div>
        </div>
    );