I'm setting up a "My account" page, I need to display the payload created after the componentDidMount() function. However, When I set my state and render it,only my email renders. How do I access the rest of the payload
import React, { Component } from "react";
import axios from "axios";
//import...
//const StyledCard
const StyledDiv = styled.div`
margin-top: 100px;
margin-right: 15px;
margin-left: 15px;
`;
class MyAccount extends Component {
state = {
data: ['default',],
};
async componentDidMount() {
const payload = { email: "tynantynan8@gmail.com",
name: "Tynan McGrady",
surname: "",
middleName: "",
number: "(805) 240-6258",
adress: "407 s. mayfair ave",};
//var payload = ["tynantynan8@gmail.com", "Tynan McGrady", " ", " ","(805) 240-6258","407 s. mayfair ave"];
await axios
.post("http://localhost:1234/user/profile", payload)
.then(res => {
const data = res.data;
console.log(data);
this.setState({
data:data
})
});
}
render() {
return (
<container>
<row>
<StyledDiv>
<StyledCard>
<Card.Header as="h5">Profile</Card.Header>
<Card.Body>
<Container>
<Row>
<p> {this.state.data.email} </p>
<p> {this.state.data.name} </p>
</Row>
</Container>
</Card.Body>
</StyledCard>
</StyledDiv>
</row>
</container>
);
}
}
export default MyAccount;
Expected results, display items on the page using this.state.data or something similar
These are the errors I get:
Objects are not valid as a React child (found: object with keys {_id, first_name, middle_name, last_name, dob, email, address, __v}). If you meant to render a collection of children, use an array instead.