1
votes

How can I handle single value which comes as obj in map method in React class component?

JSON values below:

{
  "name": "john",
  "age": 30
}

React component below:

  {this.props.test && this.props.test.map((val, key) => {
    return (
      <>
        {val._attributes.type === "25" &&
         (
            <TestComponent/>
          )}
        }
Don't destroy the edits made by people that try to make your post readable. - trincot
What is props.test? Is this the object you showed? If so - map wouldn't work for it, it is a method of arrays. If it is an array of these objects, the map function receives the element in the array as first argument, and its index as second, not the key and value (which is an objects concept) - raz-ezra