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

refactor(createUseStorageState): adjust type of defaultValue and update docs #2148

Merged
merged 8 commits into from
Jul 12, 2023

Conversation

liuyib
Copy link
Collaborator

@liuyib liuyib commented Apr 7, 2023

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

none

💡 Background and solution

Background:

In the old code, the type of defaultValue is T | IFuncUpdater<T>, IFuncUpdater is as follow:

export interface IFuncUpdater<T> {
  (previousState?: T): T;
}

This means that if defaultValue is a function, it can accept a previousState parameter, but actually, it makes no sense to do so, and there is no parameter was passed to defaultValue in real code.

So, defaultValue type just should be:

defaultValue?: T | (() => T);

By the way, this PR also do some other changes, as follow:

  1. remove useless /* eslint-disable */

  2. remove useless type definition

  3. simplify code:

    from:

    const [state, setState] = useState(() => getStoredValue());

    to:

    const [state, setState] = useState(getStoredValue);

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@liuyib
Copy link
Collaborator Author

liuyib commented Apr 7, 2023

@li-jia-nan @hchlq @miracles1919 first CR, please ❤️

@crazylxr
Copy link
Collaborator

有冲突了

@liuyib
Copy link
Collaborator Author

liuyib commented Apr 17, 2023

有冲突了

好的,稍后解决下

@liuyib liuyib changed the title refactor(createUseStorageState): make the usage of setState consistent with the document refactor(createUseStorageState): adjust type of defaultValue and update docs Apr 18, 2023
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ liuyib
❌ crazylxr
You have signed the CLA already but the status is still pending? Let us recheck it.

@crazylxr crazylxr merged commit 33caa72 into master Jul 12, 2023
@crazylxr crazylxr deleted the refactor_storage_type branch July 12, 2023 01:25
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.

None yet

4 participants