E
E
Evsand2018-11-20 13:59:14
JavaScript
Evsand, 2018-11-20 13:59:14

How to correctly enumerate a class in a template?

How to enumerate classes correctly if there are more than 1 of them? Let's say the button was wrapped in a div and had a p paragraph with unique classes ? Pass in an archive, or just enumerate classNameDiv, etc. ?

const Button = ({
  onClick,
  className = '',
  children,
}) =>
  <button
    onClick={onClick}
    className={className}
    type="button"
  >
    {children}
  </button>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-11-20
@Evsand

This is perhaps the worst path you can take.
The implementation of the bean should be encapsulated, and you should work with its interface.

<Button
  type="outline"
  size="sm"
  color="succes"
  disabled={isButtonDisabled}
  onClick={handleClick}
>
  Succes
</Button>

A
abberati, 2018-11-20
@abberati

in a good way, the internal classnames of the components should be hardwired inside the component, like this:

const WrappedButton = ({
  onClick,
  rootClassName = '',
  children,
}) =>
  <div className={rootClassName}>
    <p className="some inner classname">
      <button
        onClick={onClick}
        className="another one classname"
         type="button"
      >
        {children}
      </button>
    </p>
  </div>

but no one will forbid you to pass in props at least an object with classnames, at least an array, at least fifty props for each internal classname. if such a need arose, then most likely the component was written poorly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question