-1

I want to append some JSON data to frontend(React.js) After fetching the JSON data, I want to append the data to JSX. The data looks like below: (The value of description is string)

data = { description: "<p>Description Content</p><ul><li>list1</li><li>list2</li><li>list3</li<li>list4</li></ul>" }

I want to append this to JSX, how can I do that?

const Desctiption = ({ data }) => {
  const { description } = data;

  return (
    <div className="description-tag">

    </div>
  )
}
export default Desctiption;
0

1 Answer 1

0

Try this:

const Desctiption = ({ data }) => {
  const { description } = data;

  return (
    <div className="description-tag">
      <div dangerouslySetInnerHTML={{ __html: description }} />
    </div>
  )
}
export default Desctiption;

However this approach might be risky. Check out the docs for more information: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.