Skip to content

Instantly share code, notes, and snippets.

@officialrajdeepsingh
Created March 1, 2020 14:14
Show Gist options
  • Save officialrajdeepsingh/40dca51b9d46fafd99f8b764f6d9548e to your computer and use it in GitHub Desktop.
Save officialrajdeepsingh/40dca51b9d46fafd99f8b764f6d9548e to your computer and use it in GitHub Desktop.
How to access nested JSON object Inside Array in react js
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>
</>
);
}
}
@officialrajdeepsingh
Copy link
Author

copy code and add your project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment