I want to toggle the colors of my h1 tag. I can change the color one time to specific color. But I want to take the color to previous color when I click again.I used useState for that. In useState selected gives me true and false. According to true and false I create if statement and change the color. Here is my code
import './App.css';
import React, { useState } from 'react';
function Deneme() {
const [color,setColor]=useState('red');
const [selected, setSelected] = useState(false)
const [textColor,setTextColor]=useState('white');
if(!selected){
setColor("blue")
}
return (
<div className="App">
<button style={{background:color}} className='btn btn-primary' onClick={()=>{setTextColor('red');setSelected(!selected)}}>Click here</button>
<h1 style={{color:color}}>Change Color</h1>
</div>
);
}
export default Deneme;