Skip to content
Advertisement

React Js – Styling innerHTML on component – Not working – Parent styling is overriding child styling

I have two react components.

  1. List container
  2. List

The list needs to be inside the list container. Like so:

JavaScript

The content of both components renders. However the styling of the child is overridden by the parents styling. (In this case, the background color)

This is the full code:

JavaScript

I think it may be a similar thing to this: Style not working for innerHTML in Angular

However I cant find a React equivalent.

How can I get the list style to work?

Thank you

Advertisement

Answer

By refactoring a bit your code I found this Solution:

JavaScript

by passing props.childreninstead of innerHtml and by removing the “#” before red this works fine, see the sandbox

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement