Change font color in React-Code Examples

Victor Talmacinschi

Change font color in React

JavaScript by Victor Talmacinschi June 16, 2022

import React, { useState } from "react";

//Component to change the font color
const ChangeColor = () => {
  //useState hook to hold the font color
  const [color, setColor] = useState("red");

  //function to handle the color change
  const handleChange = (e) => {

  return (
      <h1 style={{ color: color }}>This is a Heading</h1>
      <p style={{ color: color }}>This is a paragraph.</p>
      <input type="text" onChange={handleChange} />

export default ChangeColor;



Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories