Git Product home page Git Product logo

Comments (2)

1209simran avatar 1209simran commented on August 18, 2024

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.

Shuhui11 avatar Shuhui11 commented on August 18, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.