1

everybody i have this peice of code in nodejs

<table class="invoice-items" cellpadding="0" cellspacing="0">
                                        <tbody>
                                       { ${Object.values(services).map((service)=>                                       
                                          <tr key={service.title}>
                                         <td>${service.title}</td>
                                          <td>${service.price}</td>
                                              </tr>
                                        )}}
                                      </tbody>
                                      </table>

and get this error E:\ReactCode\SoapyJoes\soapyjoes_dashboard\functions\index.js:115

 <tr key={service.title}>
                                      ^


[
   { price: '35', quantity: '1', title: 'wash&fold', weight: '2' },
   { price: '10', quantity: '3', title: 'wash', weight: '3' }
 ]

this is services values SyntaxError: Unexpected token '<'

15
  • Why do you have the $ before your map? That could be causing the syntax issue. Commented Nov 3, 2021 at 18:11
  • because it is inside var in node js html:` <table class="body-wrap"> <tbody> ${Object.values(services).map((service)=>{ return( <tr key={service.price}> <td>${service.title}</td> Commented Nov 3, 2021 at 18:14
  • I don't think that's correct... Try it without. In JSX you just use { } to use JS expressions/variables Commented Nov 3, 2021 at 18:16
  • @BrianThompson ok the error is gone but the function of the code does not work Commented Nov 3, 2021 at 18:23
  • 1
    The next steps would be to include the value of services in the question, and I would also wrap the returned JSX from the map with ( ) since multiline implicit returns can issues Commented Nov 3, 2021 at 18:26

1 Answer 1

1

enter image description here

I reproduced your code, made some changes and it was working fine for me after that. I am attaching the screenshot as well as the code for the same.

Code implemented :

import React from "react";
export default function App() {
 
 const services =  { '07b74e70-68a4-4f30-acc4-5543d37572d7': { price: '90', quantity: '4', title: 'fold', weight: '8' } }
 
 console.log(Object.entries(services))
 console.log(Object.values(services))
 
 return (
   <div>
 
   {<table style={{border:"1px solid red"}}>
                                       <tbody >
                                      {Object.values(services).map((service)=>
                                      {console.log(services)
                                        return(
                                         <div>
                                        <tr>
                                         <th> Services </th>
                                         </tr>
                                          <tr key={service.title}>
                                        <td>{service.title}</td>
                            
                                        <td>{service.price}</td>
                                       </tr>
                                       </div>
                                         )}                                     
                                      )}
                                   </tbody>
                                   </table> }                           
   </div>
)}

I hope this works for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.