Classnames Computed Keys
Here's some fun code:
import React from 'react';
import cn from 'classnames'
const App = ({ appClass }) => <div className={cn({[appClass]: !!appClass})} />
export default App
Notice the object inside className
– what's going on here?
This is a dynamic class name via ES2015+ computed keys. If appClass
is provided as a truthy prop, the class is enabled; if it is not provided or provided as a falsy prop, the class is not enabled.