Hello Guys! Hope you are fine I am new to react. I have an endpoint in spring boot and it return me an array of arrays (according to my need). but the problem is when I try to display it on react, it gives me an undefined error.
My API data will look like this;
[
[
2,
"fa ",
23,
"fajhfl",
"2021-07-20T06:44:19.000+00:00"
],
[
4,
"amdflk",
35,
"lafjoil",
"2021-07-21T06:44:43.000+00:00"
],
[
5,
"fasdf",
88,
"fajhfl",
"2021-07-22T06:44:52.000+00:00"
],
[
6,
"nm",
98,
"faldjf",
"2021-07-23T06:45:04.000+00:00"
]
]
My spring boot code is correct with proper use of Cross-origin but for question clarification, I put the Item controller code.
@RestController
@RequestMapping("/items")
@CrossOrigin(origins = "http://localhost:3000", allowedHeaders = "*")
public class ItemController {
@Autowired
private ItemService itemService;
// Get all Items
@GetMapping("/getItems")
ResponseEntity<Object> getItems(){
Object allItems = itemService.getAllItems();
if(allItems == null){
return ResponseEntity.noContent().build();
}else{
return ResponseEntity.ok(allItems);
}
}
}
Now In react I try to fetch it give me an undefined error,
<tbody className={tableStyle.tableBody}>
{props.body.map((key) => {
props.body[key].map((i, v) => {
return (
<tr>
<td key={i}>{v}</td>
</tr>
);
});
})}
But seeing this answer, I get the same error
TypeError: props.body[key].map is not a function
(anonymous function)
D:/My programming/React JS/Stock Register Managment System/srms/src/Components/GeneralTable/Table.jsx:30
27 | </thead>
28 | <tbody className={tableStyle.tableBody}>
29 | {Object.keys(props.body).map((key) => {
> 30 | props.body[key].map((i, v) => {
| ^ 31 | return (
32 | <tr>
33 | <td key={i}>{v}</td>
Thanks In Advance:)
props.body.mapinstead ofObject.keys(props.body).map