0

I am currently fetching a data table and it has 2 values needs to be mapped. Mapping works just fine but I want to add some customisation to the text.

newDataRows(
dataToBeMapped.map((m) => ({
id: m.id, data:`<span>Bold Me:</span>${m.oldData}`
})));

I was hoping to have <span> portion to be worked but I get [object Object] on my browser. Is there any way to implement HTML in this line?

3
  • How are you using this HTML? What you have is an object with two properties, one of which is a string. You may want to use a JSX element instead of a string, but that depends on how you're using it. What actually produces the incorrect output? Can you provide a minimal reproducible example which demonstrates the problem? Commented Nov 9, 2022 at 15:46
  • m.oldData is probably an object. Use JSON.stringify to parse it to text or access a text property directly. Commented Nov 9, 2022 at 15:51
  • @Wimanicesir it is an object indeed. Mbistami 's answer below just resolved my issue! Commented Nov 9, 2022 at 16:05

1 Answer 1

1

replace data:'<span>Bold Me:</span>${m.oldData}' with data: <><span>Bold me</span>m.oldData</>

And it's not HTML it is JSX
what's JSX?

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

1 Comment

the title is not projecting the issue correctly, that is my bad. Addition to your correction, thank you for the solution which works perfectly. I'll check the page you sent for sure.

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.