I'm new on React and I have a problem in this code:
class Tests extends React.Component {
async getTests() {
var url = "http://127.0.0.1:100/getTestList"
var buttons=[];
const resp = await fetch(url);
const data = await resp.json();
for(let pkg in data){
console.log(pkg);
for (let cls in data[pkg]){
console.log(cls);
for (var i = 0; i < data[pkg][cls].length; i++) {
let m= data[pkg][cls][i];
buttons.push(<button value={cls}>{m}</button>);
}
}
}
return buttons;
}
render(){
return(
<div>
<h4>Using .map()</h4>
{this.getTests()}
</div>
)
}
}//fine classe
// ========================================
ReactDOM.render(
<Tests />,
document.getElementById('root')
);
I take correctly JSON Response from POST service, iterate correctly the JSON for to have an array of buttons with value and text but I have this error on Chrome:
Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. in div (at src/index.js:95) in Tests (at src/index.js:108)
Some Tips? Thanks Regards