From 6196355e7216ea7e0bb0e0be8f9d91f821c9e612 Mon Sep 17 00:00:00 2001 From: Ze Bateira Date: Tue, 4 Feb 2020 14:48:30 +0400 Subject: [PATCH] fix: use useLayoutEffect on setup to avoid re-render on ssr apps --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index d6cad19..c6d9958 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useLayoutEffect } from 'react'; export const colorSchemes = { light: '(prefers-color-scheme: light)', @@ -40,7 +40,7 @@ export default function useSystemTheme(initialTheme) { }; }, []); - useEffect(() => { + useLayoutEffect(() => { // SSR or matchMedia not supported if (typeof window === 'undefined' || !window.matchMedia) { return;