Replies: 3 comments 11 replies
-
React Strict DOM was developed specifically to avoid regressions / rewrites on web at Meta. It enables us to take existing web code, make minor automated changes, and have it render correctly on native for the most part. (See caveats related to limited layout support on native). Is the API complete and stable on web?Yes. If you wanted, you could use RSD to build web-only apps, no problem. See the CSS and HTML compatibility tables. Note the line saying "All the APIs listed below are considered supported on Web." Is the API production ready?Yes. React Strict DOM is already used in production at Meta to render web components using React Native on VR for Facebook and Instagram. Hundreds of web components were converted to use React Strict DOM, and they continue to render in web apps like facebook.com too. What are the limitations for React Native?In many ways, the RSD API is a superset of the capabilities built-in to React Native. Although it is not a total replacement for existing React Native JS APIs, as anything without a web equivalent is by nature not included in a web-centric API. However, we are continuing to add more features to React Native that follow web specs - styles, events, etc. - so the direction of travel is towards the web. As is the case for any component library built over React Native, there is some runtime overhead. We've done extensive profiling and performance work to minimize this, but some overhead is inherent when you're adding features missing in React Native core. Over time, more of the code in RSD will move into native code within RN core, and performance will improve further. This has already been happening, with no change needed to the public API or effort on the part of product engineers. How to gradually adopt?RSD can be gradually adopted by using platform-specific files, as is already common in React Native and Expo development. You can import There's also a Mixing RSD and RN elements in the same file is not recommended. Don't mix RSD styles with RN styles either - it won't work properly at all if they are both being passed to the same element. Instead, use the import { compat } from 'react-strict-dom';
import { StyleSheet, Text } from 'react-native';
const styles = StyleSheet.create({
text: { /* styles /* }
});
export component Foo(...props: FooProps) {
return (
<compat.native
{...props}
aria-label="label"
as="text"
>
{(nativeProps: React.PropsOf<Text>)) => (
<Text {...nativeProps} style={[nativeProps.style, styles.text]} />
)}
</compat.native>
)
} Hopefully this explains how to create proper boundaries between RSD and RN, which will ensure UI renders correctly and reduce developer confusion. |
Beta Was this translation helpful? Give feedback.
-
Related question / additional example: One of the biggest fear I have observed around RN is on performance of long lists. This seems mostly a solved problem currently with FlatList, FlashList and similar. As you mentioned RSD being used in production on instagram and FB, maybe you have suggestions on how to cleanly integrate those components and similar ones. Based on your example my naive intuition is that with // VirtualList.ts (RSD file)
export function VirtualList(props: SharedPropsType) {
// use something like react-virtualized
} // VirtualList.native.ts
export function VirtualList(...props: SharedPropsType) {
return (
<compat.native {...props}>
// use FlatList
</compat.native>
} and then on other RSD or <VirtualList doStuff /> Is this correct? Or is there a different pattern/solution you recommend for this use case? Thanks again for your support. |
Beta Was this translation helpful? Give feedback.
-
Does it make sense to translate this discussion to a FAQ page on the RSD website? |
Beta Was this translation helpful? Give feedback.
-
Hi, I am evaluating different options for a component library that would target react native first, while having web as a mid/long term stretch goal.
Given the commitment and closeness of this project to React Native itself, it seems it could be a good choice.
On the other hand my understanding is that production readiness may not be there yet (especially when it comes to completeness and stability of web API)? It seems this project is to an extent already used internally, but still in a phase of requests for contributions and advocacy for gradual adoptions?
With all this in mind I have some doubts you may help clarifying.
html
components be mixed with RN primitives? Can stylex Styles be mixed with RN style objects?Sorry if I missed something from the docs. I think compat could help in reusing RN components (e.g. to use Flash/Flat Lists?).
In any case looking more for a high level recommendation considering I'm in a position where sub optimal web output is acceptable while sub optimal RN output is not, and maybe it could be a good opportunity to adopt and eventually contribute to this project?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions