bem-react icon indicating copy to clipboard operation
bem-react copied to clipboard

Matcher props must be required in the modifier's body

Open awinogradov opened this issue 6 years ago • 1 comments

interface IRatingHintProps {
  hint?: string;
}

Before:

export const withHint = withBemMod<IRatingHintProps, IRatingProps>(
  'Rating',
  { hint: '*' },
  Rating => props => (
    <Rating {...props}>
      <RatingValue base={props.base} value={props.value} />
      {props.hint && <RatingHint hint={props.hint} />}
    </Rating>
);

After:

export const withHint = withBemMod<IRatingHintProps, IRatingProps>(
  'Rating',
  { hint: '*' },
  Rating => props => (
    <Rating {...props}>
      <RatingValue base={props.base} value={props.value} />
      <RatingHint hint={props.hint} />
    </Rating>
);

props.hint must be required in the body context, because modifier applied already and we don't need to check existing of matched prop.

awinogradov avatar Jun 03 '19 14:06 awinogradov

Created a test case: https://codesandbox.io/s/infallible-chatelet-3cqw8?file=/src/index.tsx

Glazomer avatar May 04 '20 04:05 Glazomer