Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have that error:

SyntaxError Unexpected token, expected ",")

Code:

 render() {
        const {collections} = this.state;
        return (
           
            <div className='shop-page'>
                {
                  collections.map({id, ...otherCollectionProps} => {
                      <PreviewCollection key={id} {...otherCollectionProps}/>
                  })
                }
            </div>
          
        )
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
240 views
Welcome To Ask or Share your Answers For Others

1 Answer

Parentheses are needed around destructured parameters.

({ id, ...otherCollectionProps }) => ()

You should also return the JSX with either return or with simple parentheses as well (instead of curly braces).

const { collections } = this.state;
return (
  <div className="shop-page">
    {collections.map(({ id, ...otherCollectionProps }) => {
      return <PreviewCollection key={id} {...otherCollectionProps} />;
    })}
  </div>
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...