0

Add a class like this in react

 <body>

 </body>

I am expected the code bellow

 <body className="dark" >

 </body>

1
  • Show your full React component please Commented Dec 15, 2022 at 3:52

2 Answers 2

1

You can use a conditional statements to add or append classes like this:

<body className={isDarkState ? "dark" : null}>

</body>

Also, change the class to className as class is a Javascript keyword.

class is a keyword in JavaScript, and JSX is an extension of JavaScript. That's the principal reason why React uses className instead of class. Pass a string as the className prop.

Sign up to request clarification or add additional context in comments.

Comments

0

using body as root component is not recommendable. try this approach: https://stackoverflow.com/a/74429568

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.