Categories
React Answers

How to Fix the ‘Warning: Unknown DOM property class. Did you mean className?’ Error When Developing a React App?

Spread the love

Sometimes, we may run into the ‘Warning: Unknown DOM property class. Did you mean className?’ error when developing a React app.

In this article, we’ll look at how to fix the ‘Warning: Unknown DOM property class. Did you mean className?’ error when developing a React app.

Fix the ‘Warning: Unknown DOM property class. Did you mean className?’ Error When Developing a React App

To fix the ‘Warning: Unknown DOM property class. Did you mean className?’ error when developing a React app, we should make sure we replace the class attribute in our components with className.

For instance, we write:

import React from "react";

export default function App() {
  return <div className="hello">hello world</div>;
}

to assign the hello class to the div instead of:

import React from "react";

export default function App() {
  return <div class="hello">hello world</div>;
}

Conclusion

To fix the ‘Warning: Unknown DOM property class. Did you mean className?’ error when developing a React app, we should make sure we replace the class attribute in our components with className.

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 *