Skip to content

Instantly share code, notes, and snippets.

@awinogradov
Created September 11, 2018 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awinogradov/4d6bade636c2f62f9b235513436d658d to your computer and use it in GitHub Desktop.
Save awinogradov/4d6bade636c2f62f9b235513436d658d to your computer and use it in GitHub Desktop.
StateMods
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);
@awinogradov
Copy link
Author

className={list(this.props.className, block({ ololo: this.state.ololo }))}
className={this.props.className({ ololo: this.state.ololo })}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment