🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 2 Min Lesezeit
0

React with CSS Modules: Setting Styles Across Levels

↗ Quelle (dev.to)
🗣️ Stimme:

In CSS Module, all selectors are transformed, meaning that parent components cannot know the class names of child components. As a result, they cannot directly set styles across levels and have to instead control child component styles by passing props, which leads to coupling between styles and logic.



We can achieve both ensuring the uniqueness of selectors and directly setting styles for child components by simply setting both the original class name and the transformed class name together.




  • type definition




CODE
type CSSModuleClasses = { readonly [key: string]: string };

declare const classes: (
...args: ([CSSModuleClasses, string] | string | undefined | null)[]
) => string;

export { classes };







  • implementation




CODE
export const classes = (...args) =>
args
.map((x) => (Array.isArray(x) ? getClassFromModule(x[0], x[1]) : x))
.filter(Boolean)
.join(' ')

const getClassFromModule = (module, className) => {
if (!module[className]) {
throw new Error(`class name ${className} does not exist`)
}
return [className, module[className]].join(' ')
}






In js, your can set class names like this.




  • Child.tsx




CODE
import cls from './child.module.css'
import { classes } from 'css-module-classes'

export const Child = () => (
<div className={classes([cls, 'child'])}>
<div className={classes([cls, 'header'])}></div>
</div>
)






Class names of child are child _child_c3f52_1.



Class names of header are header _header_c3f52_6.




  • Parent.tsx




CODE
import { Child } from './child'
import cls from './parent.module.css'
import { classes } from 'css-module-classes'

export const Parent = () => (
<div className={classes([cls, 'parent'])}>
<Child></Child>
</div>
)






In css, use :global to target child components.




  • child.module.css




CODE
.child {
width: 100px;
height: 100px;
}

.header {
height: 10px;
background-color: red;
}







  • parent.module.css




CODE
.parent > :global(.child) > :global(.header) {
height: 100px;
}


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten React with CSS Modules: Setting Styles Across Levels

Thematisch verwandte Begriffe: React, with, Modules, Setting · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...