Skip to content
Advertisement

Received error ‘objects are not valid as a React child’ while mapping an array

Errors: –

JavaScript
JavaScript

Code

JavaScript

3.Console log of api4 arr enter image description here

How to solve these errors. Here i am trying to print the data from array Api4 but the above errors are coming.

The problem is in printing the data from the array Api4. In show function i took value of cn and cd and put in array Api 4. Then while mapping the values from Api4 i got these errors.(The error is related to either in the way of storing values of cn and cd in Api4 or in mapping of Api4 for print).

Advertisement

Answer

The issue is with this line:

JavaScript

which converts the output cd array again into an object where keys are just the array indexes.

And you should use find instead of filter to find the customer name.

You can actually simplify the whole code like this:

JavaScript

Working Demo

Edit vigilant-voice-hkzt15

Advertisement