Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rendering all nested objects from object in React

I have here this object:

 const [generic, setGeneric] = useState ({
    f1: "Hi, Stack Overflow!",
    f2: "Hello!",
  });

I want to access all childs from it.
I have some code here, but it just don’t work properly:

{Object.keys(generic).map((gen) => (
<>
<h1 key={gen}> 

{/* I also tried rendering files instead of gen, just don't work */}
</>
))

The expected result is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<h1>Hi, Stack Overflow!</h1>
<h1>Hello</h1>

>Solution :

{Object.entries(generic).map(([key, value]) => (
  
   <h1 key={key}>{value}</h1> 

 ))}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading