Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(createGlobalState)!: Align API with React.useState #1021

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nspaeth
Copy link

@nspaeth nspaeth commented Mar 4, 2020

Description

Adds support for functional updates to align with the React.useState
API. Type definitions are updated to be compatible with useState.

This might break existing code that expects functions to be held in the global
state, rather than applied as an update.

This change may also cause new type errors.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas
  • Add documentation
  • Add hook's story at Storybook
  • Cover changes with tests
  • Ensure the test suite passes (yarn test)
  • Provide 100% tests coverage
  • Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
  • Make sure types are fine (yarn lint:types).

@nspaeth nspaeth force-pushed the improve-createGlobalState-types branch 2 times, most recently from c10ad48 to 9612d69 Compare March 5, 2020 05:32
@xobotyi
Copy link
Contributor

xobotyi commented Mar 5, 2020

There is a function and types in utils for native-like state management

nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 5, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

This pull request depends on pull requests streamich#1021 streamich#979
@nspaeth
Copy link
Author

nspaeth commented Mar 5, 2020

There is a function and types in utils for native-like state management

I'll update the PR tomorrow to use those types.

@nspaeth nspaeth force-pushed the improve-createGlobalState-types branch 2 times, most recently from 0349d61 to 1e9286f Compare March 5, 2020 17:45
@nspaeth
Copy link
Author

nspaeth commented Mar 5, 2020

@xobotyi Updated.

nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 5, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

This pull request depends on pull requests streamich#1021 streamich#979
nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 5, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

This pull request depends on pull requests streamich#1021 streamich#979
nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 5, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

Previously pr streamich#786 addressed this issue by ensuring that other components
watching the key would see new updates, however, those updates would not be
rendered until something else triggered a re-render. This pr resolves that issue.

This pull request depends on pull requests streamich#1021 streamich#979
nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 5, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

Previously pr streamich#786 addressed this issue by ensuring that other components
watching the key would see new updates, however, those updates would not be
rendered until something else triggered a re-render. This pr resolves that issue.

This pull request depends on pull requests streamich#1021 streamich#979
nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 6, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

Previously pr streamich#786 addressed this issue by ensuring that other components
watching the key would see new updates, however, those updates would not be
rendered until something else triggered a re-render. This pr resolves that issue.

This pull request depends on pull requests streamich#1021 streamich#979
nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Mar 6, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

Previously pr streamich#786 addressed this issue by ensuring that other components
watching the key would see new updates, however, those updates would not be
rendered until something else triggered a re-render. This pr resolves that issue.

This pull request depends on pull requests streamich#1021 streamich#979
@nspaeth
Copy link
Author

nspaeth commented Apr 6, 2020

@xobotyi Is anything else needed in this PR, or in #1025 or #979 ?

src/createGlobalState.ts Outdated Show resolved Hide resolved
@streamich streamich changed the base branch from v14.0 to master May 16, 2020 13:58
This commit adds support for functional updates to align with the React.useState
API. Type definitions are updated to match useState.

This might break existing code that expects functions to be held in the global
state, rather than applied as an update.

This change may also cause new type errors.
@nspaeth nspaeth force-pushed the improve-createGlobalState-types branch from 1e9286f to f905c53 Compare June 20, 2020 06:38
nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Jun 20, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

Previously pr streamich#786 addressed this issue by ensuring that other components
watching the key would see new updates, however, those updates would not be
rendered until something else triggered a re-render. This pr resolves that issue.

This pull request depends on pull requests streamich#1021 streamich#979
nspaeth and others added 2 commits June 20, 2020 14:32
Makes the call synchronous to avoid race conditions, and works with SSR.
See comment at:
streamich#1060 (comment)
@nspaeth
Copy link
Author

nspaeth commented Jun 20, 2020

I've updated this PR to address comments, and to account for a comment made here, superseding #1060

@xobotyi @streamich
Is there anything more I can do to help get this or #1025 merged? I believe these PRs address a number of reported issues.

nspaeth pushed a commit to nspaeth/react-use that referenced this pull request Jul 6, 2020
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key

Previously pr streamich#786 addressed this issue by ensuring that other components
watching the key would see new updates, however, those updates would not be
rendered until something else triggered a re-render. This pr resolves that issue.

This pull request depends on pull requests streamich#1021 streamich#979
@xobotyi
Copy link
Contributor

xobotyi commented Jul 24, 2020

Watched it briefly, looks good for me.
@streamich merge is up to you.

@nspaeth
Copy link
Author

nspaeth commented Jul 25, 2020

FYI, my local branch has a couple of type improvements that I plan to commit tomorrow.

@ThomasAribart
Copy link

@nspaeth @xobotyi Is this pull request still planned to be merged ?

@nspaeth
Copy link
Author

nspaeth commented Dec 8, 2020 via email

@LRNZ09
Copy link

LRNZ09 commented Feb 25, 2021

Any update on this?

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.

5 participants