-1
I am developing a project in React and I came across a problem, I made a map in a list that works correctly, IE, if I add the objects in the api it appears on the screen, but I would like to create the function "create" with the post method and generate the field "id" in json, how do I do this?
Follow my code below:
import React from 'react';
import api from '../../api/api';
class Experiences extends React.Component {
constructor(props) {
super(props);
this.state = {
experiences: [],
};
}
async componentDidMount() {
const response = await api.get();
console.log(response);
const data = response.data.experiences.map(exp => ({
...exp,
}));
this.setState({ experiences: data });
}
render() {
const { experiences } = this.state;
return (
<>
{experiences.map(exp => (
<section key={exp.company} className="content">
<div className="experience-text">
<p className="experience-text__first">
{exp.company}
<span className="experience__date">{exp.time}</span>
</p>
<p className="experience-text_second">{exp.occupation}</p>
<p className="experience-text_second">{exp.activities}</p>
</div>
</section>
))}
</>
);
}
}
export default Experiences;
when calling the api in Insomnia, I get the following result
but would like to know how to make a CRUD and get the ID...
thank you very much for your attention
So, the correct thing is that your API already returns the ID of this data in the database.
– João Santos