Categories
JavaScript Answers

How to fix React inline style – style prop expects a mapping from style properties to values, not a string error with JavaScript?

Spread the love

Sometimes, we want to fix React inline style – style prop expects a mapping from style properties to values, not a string error with JavaScript.

In this article, we’ll look at how to fix React inline style – style prop expects a mapping from style properties to values, not a string error with JavaScript.

How to fix React inline style – style prop expects a mapping from style properties to values, not a string error with JavaScript?

To fix React inline style – style prop expects a mapping from style properties to values, not a string error with JavaScript, we set the style prop to an object with the styles.

For instance, we write

<span className="myClass" style={{ float: "left", paddingRight: "5px" }}>
  foobar
</span>

to set the style prop to an object with some style values.

Conclusion

To fix React inline style – style prop expects a mapping from style properties to values, not a string error with JavaScript, we set the style prop to an object with the styles.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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