0

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:

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

2 Answers 2

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

 ))}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

{Object.keys(generic).map((gen,index) => (
  
   <h1 key={index}>{generic[gen]}</h1> 

 ))}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.