gajus / gajus/babel-plugin-react-css-modules
Passing multiple style props to a child component
- Vorherrschende Sprache
- JavaScript
- Sterne
- 2k
- Forks
- 159
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I have a child component, which accepts multiple props for styles, one for the container, and other for one of the internal elements. Generally, I would just name them something like `className` and `elementClassName`, and get different css classes from the parent in each of the props. With `react-css-modules` though, since the default rule only allows converting `styleName` to `className`, I can not pass different local classes in multiple props, as i can only have 1 `styleName` prop.
One of the way around this seems to be to use named imports instead of anonymous imports and then pass `styles.containerClass` in className and `styles.elementClass` in `elementClassName` prop. This does not require using the `styleName` prop at all.
```
import styles from './some.css';
...
...
...
...
```
This seems alright, and the other existing `styleName` in the file do not break, still work alright and do not need to be changed to `styles.soemthing`, but it is slightly confusing that the named import is being only used at one place, and at the rest of the places the anonymous string value in `styleName` still works fine.
Is there another preferred / prescribed approach to handle the above scenario?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Es werden keine Dateien, Tests oder Einstiegspunkte genannt. Beginne damit, die Verarbeitung von styleName und benannten CSS-Modul-Imports durch das Plugin zu überprüfen, und prüfe anschließend die vorhandene Dokumentation und die Beispiele auf mehrere Style-Props. Als abgeschlossen gilt die Aufgabe, wenn ein klarer, unterstützter Ansatz identifiziert und dokumentiert wurde oder wenn das angeforderte Verhalten definiert wurde, falls die Unterstützung fehlt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100