So I have a database set up and I am trying to pull the info from it and store it into a state array so I can use it on the website.
This is an example of what I get when I request form the database, shortened for readability
{
"count": 10,
"next": null,
"previous": null,
"results": [
{
"var1": "Test",
"var2": "",
"NeededInfo": "name1",
},
{
"var1": "Test",
"var2": "",
"NeededInfo": "name2",
}
]
}
So what I need is to take the NeededInfo of each object and store it into an array so I can use it on render(). This is what I'm trying, but when I do printToConsole() (not shown but just a console.log(this.state)) to see what the state array looks like, the "other" array is undefined
const title_URL = "http://123.456.789/namelist";
class Project extends Component {
constructor(props) {
super(props);
this.state = {
random1: "",
random2: "",
other: [],
items: []
}
}
componentDidMount() {
fetch(title_URL)
.then(response => {
return response.json();
})
.then(data => {
this.setState({
other: data.results.NeededInfo
})
});
}
I need the "other" array to look like
other: ["name1", "name2"]
because in my render() I have to list the names that the site pulls from the database so the user can see the names of the listed items and do some other stuff with it, and then I can save that into the "items" array, in a new order, but that part works with if I have a preset "other" array.