Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useWindowDimensions Error on SSG render #730

Closed
bhyoo99 opened this issue Jul 5, 2023 · 1 comment
Closed

useWindowDimensions Error on SSG render #730

bhyoo99 opened this issue Jul 5, 2023 · 1 comment

Comments

@bhyoo99
Copy link

bhyoo99 commented Jul 5, 2023

Which package manager are you using? (Yarn is recommended)

yarn

Summary

import Head from "expo-router/head";
import React from "react";
import { View, Text, ScrollView, useWindowDimensions } from "react-native";

const HomeScreen = () => {
  const dimensions = useWindowDimensions();
  return (
    <>
      <ScrollView>
        <View style={{ height: dimensions.height }}>
          <Text>Home</Text>
        </View>
      </ScrollView>
    </>
  );
};

export default HomeScreen;

Then console says
Uncaught Error
Prop style did not match. Server: "height:0px" Client: "height:772px"

Minimal reproducible example

in Summary

@EvanBacon
Copy link
Contributor

Expected behavior with static rendering. You can use CSS, or create a component to avoid SSR:

import { useState, useEffect } from 'react';

export function NoSSR({ children }) {
  const [ready, setReady] = useState(false);
  useEffect(() => {
    setReady(true);
  }, [])
  if (!ready) return null;

  return children;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants