Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Add A Class In React

/*App.jsx*/

import React from 'react';

export function App(props) {
  return (
    <div className='App'>
      <h1 className="someClass">Hello React.</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}
 /*style.css*/
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  background-color: #18222d;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.App {
  color: #72a24d;
}
.someClass
{
  color: red;
}

Comment

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: react responsive nav bar 
Javascript :: auto generate component angular 
Javascript :: javascript promise state 
Javascript :: vue v-for loop array 
Javascript :: node red json array 
Javascript :: react tweet embed 
Javascript :: history react router 
Javascript :: emailjs react 
Javascript :: change parent state from child use effect in react js 
Javascript :: js summation 
Javascript :: nodelist to array 
Javascript :: remove first character javascript 
Javascript :: bind() method 
Javascript :: _.pluck 
Javascript :: arrow functions syntax 
Javascript :: crud in node 
Javascript :: discordjs 
Javascript :: binance js 
Javascript :: link in next js is refresh page 
Javascript :: send json in javascript 
Javascript :: react navbar responsive 
Javascript :: java script alerts 
Javascript :: passing functions as props in react 
Javascript :: Import A Module In ExpressJS 
Javascript :: ArduinoJson.h 
Javascript :: work with query string javascript 
Javascript :: react router 404 
Javascript :: resize window javascript 
Javascript :: javascript regex zero or more occurrence 
Javascript :: javascript get width of image 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =