EvanBacon / react-native-web-hooks

Hooks for React Native web and Expo
MIT License
197 stars 10 forks source link

SSR support #4

Closed slorber closed 4 years ago

slorber commented 4 years ago

Still trying to build https://github.com/expo/examples/tree/master/with-gatsby in production mode, with real SSR.

It's almost there, but this library does not support SSR:

image

Not sure exactly how this can be fixed. Can we compute the output of useREM on SSR?

getComputedStyle(document.documentElement).fontSize can't work on the frontend. One possibility could be to add a default fallback value for SSR, and allow to override that value through context on the server? Like <RNWHProvider value={{documentFontSize: 16}}/>?

Another option would be to provide a default fallback value as 2nd arg, like useREM(1.3, 16);

BTW, is useREM really a hook? it does not use any primitive React hook so it's just a function call (that currently only works in the browser)

EvanBacon commented 4 years ago

it's not a hook, it used to be at one point. We're in talks about different styling systems internally, it'd be nice to not have to use this method at all.

Regardless I'll work on fixing this now.

EvanBacon commented 4 years ago

Fixed in 1.0.3