Magnus UI vs. Dripsy - Chakra UI alternatives for React Native (+Web)
Published: 2021-06-10 13:59:36

>First, a primer on [React Native Web](https://necolas.github.io/react-native-web/docs/) (RNW), for those unfamiliar. RNW is taking the high-level API of React Native, onto the Web. "Why not just use React?", you say. RNW is all about using specifically tailored _native cross-platform components_ (that primarily render onto a native Screen view) and also rendering them on the web (to the DOM). Which is possible because RN/RNW uses higher-level abstractions (`<View>` and `<Text>` instead of `<div>` and `<span>`, etc.). (RNW should have been called "React Platform", really.)

If you want to use React Native or React Native Web (RNW) and want to use a component library similar to Chakra UI (which doesn't support RN [yet](https://dev.to/redbar0n/how-to-use-chakraui-on-native-mobile-53hg), and [likely won't support RNW](https://github.com/chakra-ui/chakra-ui/issues/183#issuecomment-559810732)), then you have two good alternatives, to my knowledge. Especially if you want to use NextJS to do Server-Side Rendering (SSR) of the webapp/PWA.

Here is a brief comparison of **Magnus UI vs Dripsy**:

### Both:
* React Native support
* Themed
* Inspired by Chakra UI and Theme UI
* Use `StyleSheet.create` under the hood

The differences:

### [Magnus UI](https://magnus-ui.com/)

* Utility first / atomic design methodology. "Almost all Magnus components have support for utilities like spacing, border-radius, font sizes, shadows, etc". [Example code](https://snack.expo.io/@pawankumar2901/dribble-login-page). Can remind of TailwindCSS. Meaning that all styles are direct style props on components. (This is likely not future-proof with RNW which supposes to own the top-level styling API, and has deprecated several other props like `className` in favour of having all styles passed as an object to the `style` prop).
* Has a component library: _"Magnus UI comes with a set of 25+ polished React Native components that just works out of the box."_ [magnus-ui.com](https://magnus-ui.com/)
* Not yet responsive, but [planned responsive](https://github.com/jsartisan/react-native-magnus/issues/59) with [react-native-media-queries](https://github.com/kasinskas/react-native-media-query), which makes pure CSS media queries also run on native (with device orientation). Since Magnus UI generates pure CSS media queries when run on web. [They consider it more performant than using Fresnel](https://github.com/jsartisan/react-native-magnus/issues/59). But the jury is out... Alternatively, it [might be](https://github.com/vitalets/react-native-extended-stylesheet/issues/154) that Magnus UI will use [react-native-extended-stylesheet](https://github.com/vitalets/react-native-extended-stylesheet) as a drop-in replacement for the StyleSheet in React Native which also supports media queries on native.
* Supports SSR on web via something like NextJS.

### [Dripsy](https://github.com/nandorojo/dripsy)
* Started in [Jun 2020] likely [since](https://github.com/jsartisan/react-native-magnus/issues/6) Magnus UI didn't support responsivity through CSS media query breakpoints. 
* Primarily a design system. Relies on you combining it with other React Native component libraries, or build your own on top. [nandorojo/dripsy#why](https://github.com/nandorojo/dripsy#-why). "Dripsy is an almost-drop-in replacement for React Native's UI components." from the [Readme](https://github.com/nandorojo/dripsy#usage).
* Uses the Dimensions API on Android, iOS and Web. Whether you use Dripsy [with RN](https://reactnative.dev/docs/dimensions) or [with RNW](https://necolas.github.io/react-native-web/docs/dimensions/).
* [Dripsy is very declarative](https://github.com/nandorojo/dripsy#-before--after): it allows you to provide object and array values to add mobile-first responsive styles. Instead of manually using the Dimension API (on native), and adding media queries and nested styles throughout your code (on web), Dripsy will do it for you. This API is very [inspired by Chakra UI's array syntax for declaring responsiveness](https://chakra-ui.com/docs/features/responsive-styles).
* All styles declared inside an object. Either the `style` object familiar from React Native, or a single `sx` prop. Inspired by [Theme UI's sx prop](https://theme-ui.com/sx-prop/). "Rather than have just direct style props for components, theme-ui has an sx object prop.
* [Does NOT currently support SSR](https://github.com/nandorojo/dripsy/issues/100). Even though it still works with NextJS for other reasons such as code splitting and navigation, and SSG.

These are the most important differences.

### Conclusion, my advice would be:

* If you use RNW, go with Dripsy. You get responsivity (using JS, not CSS media queries), at the price of SSR.
* If you need SSR and like the utility-first approach (similar to Tailwind), go with Magnus. You get SSR, at the price of responsivity and RNW. I'm not quite sure Magnus UI works with RNW today, but it's utility-first design is a risk that it will be less future-proof with RNW, as mentioned.
* If you want both SSR and RNW, then you are not so lucky. But you can read my research of the options you have, in this discussion: [How to combine React Native Web (RNW) + Responsive styles (media queries) + NextJS Server-Side Rendering (SSR), to get SEO on the web](
https://github.com/nandorojo/dripsy/discussions/109#discussioncomment-848718). If you don't want to make a compromise like the current options, there is a library called Fresnel, which has some promise to afford this combination. But it is not quite there yet. So please consider contributing to Fresnel in [the RNW+NextJS compatibility issue](https://github.com/artsy/fresnel/issues/183) or the [useMedia() hook issue](https://github.com/artsy/fresnel/issues/166#issuecomment-856231766), so that [Dripsy could be upgraded](https://github.com/nandorojo/dripsy/discussions/109#discussioncomment-848718) to use Fresnel again to support SSR.

## The problem of SSR + Responsivity

Read on, if you are interested in how Dripsy worked before it dropped SSR:

Dripsy used media queries and the SSR library Fresnel to accomplish Responsivity with SSR. Now it uses Dimensions API which determines responsive layouts in JS instead of with media queries in CSS on the web. This is to stay close to the API of RNW, which presumes you determine window dimensions in JS, which entails Client-Side Rendering (CSR), since `window` in JS is only available on the client. In short.

Before, Dripsy used a library called [Fresnel](https://github.com/artsy/fresnel) to achieve achieve Responsivity with CSS media queries. CSS breakpoints on web will rely on the mobile device's user agent for most cases. But since this can be inaccurate, Fresnel also uses [pre-emptive server-side breakpoint generation](https://artsy.github.io/blog/2019/05/24/server-rendering-responsively/). Basically, if the mobile user-agent cannot be _accurately_ detected (if you combine Fresnel with its sister library, [detect-responsive-traits](https://github.com/artsy/detect-responsive-traits)), then Fresnel will render _all_ media query breakpoints on the server (a bit of extra work for the server, since it might lead to rendering more components). So the client's browser will receive all breakpoints on first render and can immediately start rendering according to the correct ones. Instead of waiting for React to rehydrate before only then running the media queries with CSS-in-JS, which would have given latency and potentially unwanted visual side-effects. This becomes most acute when you are using SSR, and thus don't want to wait for rehydration on the client to start showing the responsively laid out content.

> "Basically, it comes down to this: when using server-side rendering, every component's props on the first render on the client side must be the exact same as their props on the server's render. Since we use the screen size to determine which style to apply, and this is done using JS, it's possible that the props on the server and client won't match. This happens because the server doesn't know what the screen size will be on the client." - [Fernando Rojo of Dripsy](https://github.com/nandorojo/dripsy/issues/4#issuecomment-657093656)

So if you want a design system / component library for React Native, then either of Magnus UI or Dripsy seems the way to go, instead of using Chakra UI, [currently](https://dev.to/redbar0n/how-to-use-chakraui-on-native-mobile-53hg).

But you have some other options if you are determined to [use Chakra UI on mobile](https://dev.to/redbar0n/how-to-use-chakraui-on-native-mobile-53hg), and are willing to sacrifice using RN/RNW.