02.07 React State - font color from input (class components)

adriangheo

adriangheo

Posted on October 23, 2022

02.07 React State - font color from input (class components)

App preview:
The way the app will look like

Project files:
An image of project file structure


import React from "react";
import "./App.css"

class App extends React.Component{
  state = {
    color: 'darkBlue'
  };

  handleColorChange(event){
    console.log(event.target.value);
    this.setState({color: event.target.value})
  }

  render() {
    return (
      <div className="app" style={{color: this.state.color}}>
        <h1>Hello World!</h1>
        <input type="input" onChange={(event)=>this.handleColorChange(event)}></input>
      </div>
    )
  }
}

export default App;
Enter fullscreen mode Exit fullscreen mode

.app{
    background-color: lightskyblue;
    padding: 20px 10px;
}
Enter fullscreen mode Exit fullscreen mode
πŸ’– πŸ’ͺ πŸ™… 🚩
adriangheo
adriangheo

Posted on October 23, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related