Thanh Vinh
Thanh Vinh

Reputation: 95

ReactJs - Expected an assignment or function call and instead saw an expression

I did take a research on stackoverflow and received some results which is still not helping me solving this different problem properly. (differences between function and class)

(Expected an assignment or function call and instead saw an expression no-unused-expressions.) at the line <Product7 key= {products7.id} from that.

I am new to this subject. I really appreciate if anyone could help me ^_^ . Many thanks.

function App() {
  var products7 = [
            {
                 name: 'Hollow Knight',
                 id : 1,
                 price: '3$',
                 status : true,
                 image: 'https://yuzu-emu.org/images/game/boxart/hollow-knight.png'
            },

            {
                 name: '60 Second!',
                 id : 2,
                 price: '4$',
                 status : true
                 image: 'https://yuzu-emu.org/images/game/boxart/hollow-knight.png'

            },

            {
                 name: 'Valiant Heart',
                 id : 3,
                 price: '5$',
                 status : true
                 image: 'https://yuzu-emu.org/images/game/boxart/hollow-knight.png'

            },
  ];

  let elements = products7.map((Product7, index) => {
       
       return     

<Product7 key= {products7.id}
          image={products7.image} 
          price={products7.price} > 

          {products7.name}


           </Product7>


  });

Upvotes: 0

Views: 213

Answers (2)

Sarthak Aggarwal
Sarthak Aggarwal

Reputation: 2312

Your return statement is not proper. Try this

let elements = products7.map((product7, index) => { // variable name updated
       
       return (    
          <Product7 key= {products7.id}
          image={products7.image} 
          price={products7.price} > 
          {products7.name}
          </Product7>
         )

  });

Upvotes: 2

Anku Singh
Anku Singh

Reputation: 954

You need to wrap your return code inside map

 let elements = products7.map((Product7, index) => {
       
       return (     

         <Product7 key= {products7.id}
          image={products7.image} 
          price={products7.price} > 

          {products7.name}


           </Product7>)


  });

Upvotes: 2

Related Questions