Skip to content

Conversation

@jharrilim
Copy link
Collaborator

Also refactored a test that was causing a warning

#50

let [name, setName] = useLocalStorage(key, 'default value');
React.useEffect(() => {
setName('key1 name');
setTimeout(() => set('key2'));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This setTimeout was causing problems, so it is now removed; the key is updated simply through a button click.


const [timEditAgeButton] = await findAllByTestId(allPeople[0]);

act(() => void fireEvent.click(timEditAgeButton));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

act not needed for fireEvent

export function useLocalStorage<TValue = string>(
key: string,
initialValue?: TValue
): [TValue | null, Dispatch<TValue>, Dispatch<void>] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

return type inferred from the chosen overload

@iamsolankiamit iamsolankiamit merged commit 8e0d2ff into master Mar 26, 2020
@jharrilim jharrilim mentioned this pull request Mar 28, 2020
iamsolankiamit added a commit that referenced this pull request Apr 30, 2020
* 'master' of github.com:rehooks/local-storage:
  Add prepublishOnly script
  Create npmpublish.yml
  Patch for issue #53 (#54)
  Fix for #50 \n\nAlso refactored a test that was causing a warning (#51)
  Support false values with a true fallback value (#48)
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

Successfully merging this pull request may close these issues.

3 participants