Use the useState hook to set the state of the variables. You can then use the variables in your HTML attributes.
const [background, setBackground] = useState("black")
console.log(background()) // black
setBackground("red")
console.log(background()) // red
Use the useEffect hook to trigger custom actions whenever the state changes.
// Empty useEffect for on load:
useEffect(() => {
console.log("Initial useEffect render")
}, [])
// One useEffect:
useEffect(() => {
console.log("background:", background())
}, [background])
// More than one useEffect:
useEffect(() => {
console.log("textColour:", textColour(), "background:", background())
}, [background, textColour])
Use the useState hook to set the state of the variables. You can then use the variables in your HTML attributes (like class and style), and soon in your innerHTML.
// Set initial variables:
const [background, setBackground] = useState("black")
// Inline style:
<h1 style="background: {background}">Welcome</h1>
// Or in Tailwind:
<h1 className={"bg-{background}"}>Welcome</h1>