Comments (2)
Hey @Shuhui11
JSON for customer1 should look like this:-
[
{
"id": 1,
"name": "ABCD",
"email": "[email protected]",
"phone": "123456789"
},
{
"id": 2,
"name": "QWER",
"email": "[email protected]",
"phone": "987654321"
},
{
"id": 3,
"name": "ABNSD",
"email": "[email protected]",
"phone": "123412345"
}
]
CustomerDetails should look like this
import React, { Component } from "react";
import Panel from "react-bootstrap/lib/Panel";
import axios from "axios";
//This Component is a child Component of Customers Component
export default class CustomerDetails extends Component {
constructor(props) {
super(props);
this.state = {};
}
//Function which is called when the component loads for the first time
componentDidMount() {
this.getCustomerDetails(this.props.val);
}
//Function which is called whenver the component is updated
componentDidUpdate(prevProps) {
//get Customer Details only if props has changed
if (this.props.val !== prevProps.val) {
this.getCustomerDetails(this.props.val);
}
}
//Function to Load the customerdetails data from json.
getCustomerDetails(id) {
axios.get("assets/samplejson/customer" + id + ".json").then(response => {
this.setState({ customerDetails: response });
});
}
render() {
if (!this.state.customerDetails) return
Loading data
;return (
{this.state.customerDetails.data.map(customer => (
<Panel.Heading>
<Panel.Title componentClass="h3">{customer.name}</Panel.Title>
</Panel.Heading>
))}
);
}
}
from simple-reactjs-app.
Hi @1209simran
It works! That helps a lot! Thank you for the prompt guidance. I am new and learning.
from simple-reactjs-app.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-reactjs-app.