Skip to content

Commit

Permalink
fix: useEffect is now defined
Browse files Browse the repository at this point in the history
Fixes #1787
  • Loading branch information
tannerlinsley committed Feb 12, 2021
1 parent f9f9cce commit 627560f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/devtools/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ const getItem = key => {
export default function useLocalStorage(key, defaultValue) {
const [value, setValue] = React.useState()

useEffect(() => {
React.useEffect(() => {
const initialValue = getItem(key)

if (typeof initialValue === 'undefined' || initialValue === null) {
setValue(typeof defaultValue === 'function' ? defaultValue() : defaultValue)
setValue(
typeof defaultValue === 'function' ? defaultValue() : defaultValue
)
} else {
setValue(initialValue)
}
}, []);
}, [])

const setter = React.useCallback(
updater => {
Expand Down

1 comment on commit 627560f

@vercel
Copy link

@vercel vercel bot commented on 627560f Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.