Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why Map value are not displaying inside modal body in react bootstrap

I have a requirment, when i click on a button i should display a modal popup box using react bootstrap.

But the value is not displaying inside modal body.
when I puted log, in the console it is printing all the values. But the same value I want to try to print on the modal body is not printing.

here is the sample code
`
function MyVerticallyCenteredModal(props) {

return (

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  <Modal scrollable={true}
     {...props}
     size="lg"
     aria-labelledby="contained-modal-title-vcenter"
     centered
  >
     <Modal.Header closeButton>
        <Modal.Title id="contained-modal-title-vcenter">
           Order Id - {props.order.orderId}
        </Modal.Title>
        
     </Modal.Header>
     <Modal.Body>
        <table>
           <tbody>
              {
                 
                 props.order.foods.map((food,id)=>{
                    console.log(food);
                    <tr>
                       <td>{food}</td>
                    </tr>
                 })
              }
           </tbody>
        </table>
     </Modal.Body>
     <Modal.Footer>
        {/* <Button onClick={props.onHide}>Close</Button> */}
     </Modal.Footer>
  </Modal>

);
}`

  1. Can anyone help me how to solve this problem

     Thanks in advance.
    

>Solution :

you have not used return in your code, that’s why your map does not return anything, try this,

 <tbody>
              {
                 
                 props.order.foods.map((food,id)=>{
                    console.log(food);
                   return (
                       <tr>
                         <td>{food}</td>
                       </tr>
                        )
                 })
              }
           </tbody>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading