I'm trying to remove an attripute from html element using on click on a button:
import React , {useState} from 'react';
import classNames from 'classnames';
function App () {
const [isActive, setIsActive] = useState(false);
const handleOnClick = () => {
setIsActive(!isActive);
};
return (
<InlineBlockLogIn
className={classNames('active', { 'active' : isActive})}
onClick={handleOnClick} >
<InlineBlockReg
className={classNames('', { 'active' : isActive})}
onClick={handleOnClick} >
)};
I would like to remove the "active" from InlineBlockLogIn when clicked on the InlineBlockReg and so on. So basically if active at one div it should be inactive at the second one. Any idea how to do so please?
The code in your question does not have a single root element, is missing closing tags and the handlers are not correct. Maybe the following code can help you: