ReactJs – Uncaught Error: Invariant Violation: The `style` prop expects a mapping from style properties to values, not a string.

We cant directly assign css properties to the style attribute like inline style in ReactJs. If you are using css properties with style attribute in react, then you will get this error on run time “Uncaught Error: Invariant Violation: The `style` prop expects a mapping from style properties to values, not a string.“.

For this issue resolve, you can use style property like below.

var divStyle = {
  color: '#444',
  width: 150px,
  height: 10px
};
ReactDOM.render(<div style={divStyle}>Hello World!</div>, mountNode);

Leave a Reply

Your email address will not be published. Required fields are marked *