I am using javascript and react-js to try to change the color of the "exclude" button when I click on it from white to red. If I click it again I want it to change back to white. I am doing this in the button tag and trying to use useState. I included the app.js file and app.css file. I can not get it to work. Please help!
function App() {
const classes = useStyles()
const [prev, changeColor] = useState(1)
return (
<div className="App">
<header className="App-header">
<Box
sx={{
display: 'grid',
gap: 1,
gridTemplateColumns: 'repeat(2, 1fr)',
gridTemplateRows: 'auto',
gridTemplateAreas: `"header header header header"
"main main . sidebar"
"footer footer footer footer"`
}}
>
<Grid container spacing={12}>
<Grid item md={12}>
<Paper className=" "> Tag </Paper>
</Grid>
<Grid item xs={6} md={8}>
<Box
className={clsx(classes.containerBox, classes.containerBox)}
></Box>
<Button
id="excluded"
onClick={() => changeColor(prev => (prev === 1 ? 0 : 1))}
href="# "
variant="contained"
size="medium"
style={{
fontSize: 20
//backgroundColor: bg ===1 ? "white" : "red"
}}
color="tertiary"
>
Exclude
</Button>
</Grid>
</Grid>
</Box>
</header>
</div>
)
}
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
button {
padding: 10px 20px;
margin: 5px;
background-color: grey;
border-radius: 5px;
}