In my React/Typescript project, I have a challenge:
From the Child component I pass a prop
classdown:Child class={{ myBanner: styles.myBanner } />I typed
classprop as follows:import { SerializedStyles } from '@emotion/react'; import { Class as MyCustomBannerClass } from './MyBanner/MyBanner.types'; type Class = Partial<Record<'root', SerializedStyles>> & { myBanner: MyCustomBannerClass; }; export type Props = { class: Class; };
Inside Child component I have
<MyBanner/>component, where I also have aclassprop:export type Class = Partial<Record<'root', SerializedStyles>>; export type Props = { class?: Class; }; <MyBanner class={props.class?.myBanner} />
This is all working fine.
Now from within Parent component, through Child and <MyBanner/>,
I am able to override a css style in Parent from <MyBanner /> component.
The challenge:
Now I have a case:
Inside Child, I have another child
<AnotherChild/>.And within
<AnotherChild />, I have<MyBanner/>component.
Question:
How do I pass and type class={{ myBanner: styles.myBanner } through both...
Child:
<Child class={{ myBanner: styles.myBanner } />And AnotherChild:
<AnotherChild class={???} />
...and pass it down to <MyBanner class={props.class?.myBanner} />?