Asdfg
Asdfg

Reputation: 12203

unable to render html from function

I am trying to loop thru JSON object and return values in h1 and display on UI. This is how my function looks like:

const error_messages = Object.entries(props.feedback?.messages.json || {}).forEach((key, value) => {
    console.log(key, value)
    return (<h1>{value}</h1>)
}
)

This is how I am calling it:

<div>
{error_messages}
</div>

I can see the values being printed in the console but no h1s are rendered in the div.

What am I missing here?

Upvotes: 1

Views: 22

Answers (1)

Viet Dinh
Viet Dinh

Reputation: 1951

You are using forEach. That's function will return nothing to assign.

Let try change it to map instead.

Upvotes: 1

Related Questions