Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

use state in className

Standard fair:

const [toggleClass, setToggleClass] = useState(false)

return <div className={toggleClass ? 'some-class' : ''} /> 
Using template literals:

const [toggleClass, setToggleClass] = useState(false)

return <div className={`some-class ${toggleClass ? 'some-class' :''}`} /> 
 
PREVIOUS NEXT
Tagged: #state #className
ADD COMMENT
Topic
Name
4+6 =