Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to Add a Class in JSX

/* We can add attributes to the JSX elements, 
for example id and class, the same as in HTML! */

import React from "react";
import ReactDOM from "react-dom";

const App = () => {
  const id = "some-id";
  return (
    <div>
      <h1 id={id}>This is a heading</h1>
      <h2 className="active">This is another heading</h2>
    </div>
  );
};

/* Note that in React, we need to use className instead of class.*/

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Add #Class #JSX
ADD COMMENT
Topic
Name
8+6 =