Replies: 3 comments 1 reply
-
the nesting of multiple |
Beta Was this translation helpful? Give feedback.
-
This idea of a function to separate native props from React Strict DOM (RSD) props is quite compelling. It could lead to better type safety and prevent unexpected behavior by ensuring that components receive only the props they are designed to handle. From a TypeScript perspective, this could potentially be implemented using utility types like interface NativeDivProps extends React.HTMLAttributes<HTMLDivElement> {
// Define native div props here
}
interface RsdDivProps {
// Define RSD specific props here
rsdVariant?: 'primary' | 'secondary';
}
type SeparatedProps = {
native: NativeDivProps;
rsd: RsdDivProps;
};
function separateProps<T extends NativeDivProps & RsdDivProps>(props: T): SeparatedProps {
const { rsdVariant,...native } = props;
const rsd: RsdDivProps = { rsdVariant };
return { native, rsd };
}
// Usage example:
const combinedProps = { className: 'my-div', onClick: () => {}, rsdVariant: 'primary' };
const { native, rsd } = separateProps(combinedProps);
// native will be { className: 'my-div', onClick: () => {} }
// rsd will be { rsdVariant: 'primary' } |
Beta Was this translation helpful? Give feedback.
-
We need to use components to set the correct contexts in various scenarios. You shouldn't be reaching for this API very often |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello dear RSD team
We are implementing an interop layer on our app but we still want to use
ScrollView
which has no built-in support by RSD.So we came up with this solution for the native part following the advice here:
CustomScrollView.native.ts
But there are a couple of tiny issues here:
props
we have props that are not compatible withrsd
's<html.div>
so when we spread it (<compat.native style={style} {...props}>
) we get an error that there are invalid props. We have two options now:{...props}
: The issue is that we still want the props (especially a11y) to be processed byuseNativeProps
CustomScrollViewProps
, I have to definecontentContainerStyle?: Parameters<typeof h.div>[0]["style"];
because as far as I can tell, the props aren't exported from the module. Is there a way to use it in a cleaner way?I would appreciate your advice here
Beta Was this translation helpful? Give feedback.
All reactions