Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react JSON data to display in a table

<tbody>
{
  Object.keys(this.state.birth_details).map(function (element) {
    return (
      <tr key={element}>
        <td>{element}</td>
        <td>{this.state.birth_details[element]}</td>
      </tr>
    );
  })
}
</tbody>
Comment

display json data in html table react

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { useState, useEffect } from 'react';
import '../tabledata.css';
 
function TableData() {
    const [data, getData] = useState([])
    const URL = 'https://jsonplaceholder.typicode.com/posts';
 
    useEffect(() => {
        fetchData()
    }, [])
 
 
    const fetchData = () => {
        fetch(URL)
            .then((res) =>
                res.json())
 
            .then((response) => {
                console.log(response);
                getData(response);
            })
 
    }
 
    return (
        <>
            <h1>How to display JSON data to table in React JS</h1>
            <tbody>
                <tr>
                    <th>User Id</th>
                    <th>Id</th>
                    <th>Title</th>
                    <th>Description</th>
                </tr>
                {data.map((item, i) => (
                    <tr key={i}>
                        <td>{item.userId}</td>
                        <td>{item.id}</td>
                        <td>{item.title}</td>
                        <td>{item.body}</td>
                    </tr>
                ))}
            </tbody>
 
        </>
    );
}
 
export default TableData;
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is react reveal 
Javascript :: javascript switch items in array 
Javascript :: template strings in es6 
Javascript :: loop into array javascript 
Javascript :: find number in array js 
Javascript :: owl carousel for react 
Javascript :: declaring two variables inside for loop 
Javascript :: Forward propagation in NN 
Javascript :: longest string 
Javascript :: prevent history back javascript 
Javascript :: javascript fade color 
Javascript :: import math javascript 
Javascript :: json parameter name javascript 
Javascript :: how to change Mime type of a file express 
Javascript :: string equals javascript 
Javascript :: Anonymous Functions with arguments in JavaScript 
Javascript :: npm fund 
Javascript :: javascript await keyword 
Javascript :: js summation 
Javascript :: context api example in react 
Javascript :: string to code javascript 
Javascript :: react native setTimeOut error 
Javascript :: set default value in dropdown angular 7 
Javascript :: bonjour 
Javascript :: what is prototype in javascript 
Javascript :: javascript if equal infinity 
Javascript :: angular auth guard 
Javascript :: notify.js 
Javascript :: lazy loading by scroll vue 
Javascript :: react infinte scroll 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =