I have this state
const [value, setValue] = useState([]) // init with empty array
Which I set like this
async function createSalesOrder () {
const res = await axios.post('http://localhost:5000/')
setValue([...value, res.data])
return (res)
}
And then I get the Objects are not valid as a React child error
This is how res looks
data: {salesOrderId: "9000002031"}
status: 200
statusText: "OK"
headers: {content-length: "29", content-type: "application/json; charset=utf-8"}
config: {url: "http://localhost:5000/", method: "post", headers: {…}, transformRequest: Array(1), transformResponse: Array(1), …}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
__proto__: Object
And this is how it the values is used in the returned method
<tbody>
<tr>
<td>1</td>
<td>{value.map((item, i) => <p key={i}>{item}</p>)}</td>
</tr>
</tbody>
value
state to render in thereturn
of the component. - rockfight