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

using props to get value from a table

I am trying to build one table using props, and pass the value from that table to another function. But for some reason, the result is not displaying. What have I done wrong?

import Table from "https://cdn.skypack.dev/react-bootstrap@2.5.0";

function Tables(props) {
  
  return (
  <Table>
    <thead>
      <tr>
        <th>a</th>
        <th>b</th>
        <th>c</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>{props.first}</td>
        <td>{props.second}</td>
        <td>{props.third}</td>
      </tr>
    </tbody>
  </Table>
      )
}

function App() {
  return (
    <div>
      <Tables first="Sara" />
      <Tables second="Cahal" />
      <Tables third="Edite" />
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

>Solution :

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

You are rendering the table three times, each one with only one prop, you need to

If you want to show one table with the three props, it should be like that.

import Table from "https://cdn.skypack.dev/react-bootstrap@2.5.0";

function Tables(props) {
  
  return (
  <Table>
    <thead>
      <tr>
        <th>a</th>
        <th>b</th>
        <th>c</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>{props.first}</td>
        <td>{props.second}</td>
        <td>{props.third}</td>
      </tr>
    </tbody>
  </Table>
      )
}

function App() {
  return (
    <div>
      <Tables first="Sara" second="Cahal" third="Edite" />
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

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