Skip to content

Commit

Permalink
fix: use useLayoutEffect on setup to avoid re-render on ssr apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Ze Bateira committed Feb 4, 2020
1 parent 386fdcc commit 6196355
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useLayoutEffect } from 'react';

export const colorSchemes = {
light: '(prefers-color-scheme: light)',
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function useSystemTheme(initialTheme) {
};
}, []);

useEffect(() => {
useLayoutEffect(() => {
// SSR or matchMedia not supported
if (typeof window === 'undefined' || !window.matchMedia) {
return;
Expand Down

0 comments on commit 6196355

Please sign in to comment.