02.10 React State - bg color change with color picker (functional components)
adriangheo
Posted on October 24, 2022
src/App.js
import React, { Component, useState } from 'react'
import './App.css';
const App = () => {
const [background, changeColor] = useState("lightBlue");
const handleBackroundChange = (event) => {
console.log(event.target.value);
changeColor( event.target.value)
}
return (
<div className="App" style={{background: background}}>
<h1>Hello World!</h1>
<input type="color" onChange={(event)=>handleBackroundChange(event)}></input>
</div>
)
}
export default App
src/App.css
.App {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
π πͺ π
π©
adriangheo
Posted on October 24, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript Mastering React Performance: In-Depth Guide to useCallback and useMemo. π
November 24, 2023
javascript Rewrite styled-components in ReactJS with just 60 lines of JavaScript code
September 29, 2023