Created
September 11, 2018 16:49
-
-
Save awinogradov/4d6bade636c2f62f9b235513436d658d to your computer and use it in GitHub Desktop.
StateMods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { cn, ClassNameFormatter } from '@bem-react/classname'; | |
import { withBemClassName } from '@bem-react/core'; | |
const block = cn('Block'); | |
interface IBlockProps { | |
wow?: string; | |
className?: ClassNameFormatter; | |
} | |
interface IBlockState { | |
ololo: boolean; | |
} | |
const mapPropsToBemMods = ({ wow }: IBlockProps) => ({ wow }); | |
const mapStateToBemMods = ({ ololo }: IBlockState) => ({ ololo }); | |
class BlockPresenter extends React.Component<IBlockProps, IBlockState> { | |
componentDidMount() { | |
this.setState({ ololo: true }); | |
} | |
render() { | |
const stateMods = mapStateToBemMods(this.state); | |
const classString = this.props.className(stateMods); | |
return <div className={classString} />; | |
} | |
} | |
export const Block = withBemClassName(block, mapPropsToBemMods)(BlockPresenter); |
Author
awinogradov
commented
Sep 11, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment