Created
October 25, 2020 16:15
-
-
Save misss-popcorn/139660786c831d4fa3c043e9ed54d1b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useEffect} from "react"; | |
export function UseEffectFunc() { | |
const [name, | |
setName] = useState(""); | |
const [textColor, | |
setTextColor] = useState("white"); | |
useEffect(() => { | |
const ColorCode = "rgb(" + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + ")"; | |
setTextColor(ColorCode); | |
},[name]); | |
const handleChange = (e) => { | |
setName(e.target.value); | |
}; | |
return ( | |
<span className="Right"> | |
<p style={{ | |
"color": textColor | |
}}>Function Component</p> | |
<input value={name} onChange={handleChange}></input> | |
</span> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment