0

The following component:

import React from 'react';

const container = ({ items }) => (
    <div
      dangerouslySetInnerHTML={{
        __html: items,
      }}
    />
);
export default container;

returns:

<div classname="myDiv"></div>

I'm trying to replace classname with class, but not sure how to do so.

I tried different ways for example this without any success:

    <div
      dangerouslySetInnerHTML={{
        __html: items.replace('classname', 'class')
      }}
    />

How can I replace the string inside the props?

user1941537
  • 6,097
  • 14
  • 52
  • 99
  • have you tried `replaceAll`? maybe you have multiple strings – Georgy Mar 18 '22 at 18:05
  • is `items` a string? If you can somehow get the DOM object for the element it would be much easier. – ca1c Mar 18 '22 at 18:06
  • Here is an answer to your question [link](https://stackoverflow.com/questions/53539885/how-to-pass-style-using-dangerouslysetinnerhtml-in-react/68278282#68278282) – Aaron Vasilev Mar 18 '22 at 18:07

0 Answers0