DEV Community

adriangheo
adriangheo

Posted on

02.06 React State - font color switch (functional components)

App preview:
The way the app will look like

Project files:
An image of project file structure


src/App.js

import React, { useState } from "react";
import "./App.css"

function App(){
  const [color, setColor] = useState('red');

  return (
    <div className="app" style={{color: color}} >
      <h1>Text color is {color}.</h1>
      <button onClick={() => setColor("blue")} >Blue</button>
      <button onClick={() => setColor("red")}>Red</button>
    </div>
  );
}

export default App;
Enter fullscreen mode Exit fullscreen mode

src/App.css

.app{
    background-color: lightskyblue;
    padding: 20px 10px;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)