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) => {
    setColor(e.target.value);
  };

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

export default ChangeColor;

0

21.937

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories