Skip to content

Commit

Permalink
fix: persistTheme is not memoized properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Bereghici committed Dec 19, 2021
1 parent 7999103 commit c33d931
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/theme-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ function ThemeProvider({
})

const persistTheme = useFetcher()
// TODO: remove this when persistTheme is memoized properly
const persistThemeRef = React.useRef(persistTheme)
React.useEffect(() => {
persistThemeRef.current = persistTheme
}, [persistTheme])

const mountRun = React.useRef(false)

Expand All @@ -58,7 +63,10 @@ function ThemeProvider({
}
if (!theme) return

persistTheme.submit({theme}, {action: themeAction, method: 'post'})
persistThemeRef.current.submit(
{theme},
{action: themeAction, method: 'post'},
)
}, [theme])

React.useEffect(() => {
Expand Down

0 comments on commit c33d931

Please sign in to comment.