Skip to content

Instantly share code, notes, and snippets.

@misss-popcorn
Created October 25, 2020 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misss-popcorn/139660786c831d4fa3c043e9ed54d1b0 to your computer and use it in GitHub Desktop.
Save misss-popcorn/139660786c831d4fa3c043e9ed54d1b0 to your computer and use it in GitHub Desktop.
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