Display JSON Data using map Function with React Component | IndianTechnoEra - IndianTechnoEra
Latest update Android YouTube

Display JSON Data using map Function with React Component | IndianTechnoEra

Create a JSON file, which has student details such a register number, name, department, and display the same in react component using the map functio
Display JSON Data using map Function with React Component | IndianTechnoEra


Aim:

 Create a JSON file, which has student details such a register number, name, department, and display the same in react component using the map function.

Component 1: JSON Data Part

Student.json

[

    {"Name": "Sam","Branch": "CSE","Roll": "101", "RegNo":"8989898989"},

    {"Name": "Sid","Branch": "ECE","Roll": "102", "RegNo":"7979797979"},

    {"Name": "Edward","Branch": "CSE","Roll": "103", "RegNo":"8787878787"},

    {"Name": "Andrew","Branch": "Bio","Roll": "104", "RegNo":"9797979797"}

]



Component 2:  JSON Data Manage Part

JsonDataDisplay.js

import JsonData from './Student.json'

import './JsonDataDisplay.css'

function JsonDataDisplay () {

  const DisplayData = JsonData.map(data => {

    return (

      <tr>

        <td> {data.Name} </td>

        <td> {data.Branch} </td>

        <td> {data.Roll} </td>

        <td> +91 {data.RegNo} </td>

      </tr>

    )

  })

  return (

    <div>

      <table className='table'>

        <thead>

          <tr>

            <th>Name</th>

            <th>Branch</th>

            <th>Roll</th>

            <th>Register No.</th>

          </tr>

        </thead>

        <tbody>

            {DisplayData}

        </tbody>

      </table>

    </div>

  )

}

export default JsonDataDisplay;


Component 3:  CSS Part

JsonDataDisplay.css

table{width:350px;font-size:25px;align-items:center}

th{border:2px solid #000;color:#04ff96;width:100px}

td{border-bottom:2px dotted #898989}


Component 4:  Index Part

index.js

import ReactDOM from 'react-dom/client'

import React from 'react'

import JsonDataDisplay from './JsonDataDisplay'

const root = ReactDOM.createRoot(document.getElementById('root'))

root.render(

  <>

    <React.StrictMode>

      <JsonDataDisplay />

    </React.StrictMode>

  </>

)



Output:


إرسال تعليق

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.