Created
March 1, 2020 14:14
-
-
Save officialrajdeepsingh/40dca51b9d46fafd99f8b764f6d9548e to your computer and use it in GitHub Desktop.
How to access nested JSON object Inside Array in react js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from "react"; | |
//react bootstrap components | |
import CardDeck from "react-bootstrap/CardDeck"; | |
import Card from "react-bootstrap/Card"; | |
import Container from "react-bootstrap/Container"; | |
import Row from "react-bootstrap/Row"; | |
//scss | |
import style from "./styles.module.scss"; | |
//data for post | |
import data from "./data.json"; | |
export default class DefaultPost extends Component { | |
render() { | |
return ( | |
<> | |
<Container fluid={true}> | |
<Row> | |
<CardDeck className=' no-gutters '> | |
{data.map((postData) => { | |
console.log(postData); | |
return ( | |
<Card key={postData.id}> | |
<Card.Img variant="top" src={postData.image} /> | |
<Card.Body> | |
<Card.Title className={style.tile}> | |
{postData.title} | |
</Card.Title> | |
<Card.Subtitle className={style.tag}> | |
{postData.tag + " "} | |
</Card.Subtitle> | |
<Card.Text className={style.para}> | |
{postData.body} | |
</Card.Text> | |
</Card.Body> | |
</Card> | |
); | |
})} | |
</CardDeck> | |
</Row> | |
</Container> | |
</> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy code and add your project