-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: added 'create' and 'shallow' imports to docs #2028
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1feb95f:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on it! Here are some suggestions.
Ok for that, I will change this- |
And the last question- Now, I don't think the purpose of this doc is about shallow, so how about changing like this?" |
If you summarize all the changes that I need to make, it's will be great. |
This will be the final result (if it works without errors): import { create } from 'zustand'
type State = {
firstName: string
lastName: string
}
type Action = {
updateFirstName: (firstName: State['firstName']) => void
updateLastName: (lastName: State['lastName']) => void
}
// Create your store, which includes both state and (optionally) actions
const usePersonStore = create<State & Action>((set) => ({
firstName: '',
lastName: '',
updateFirstName: (firstName) => set(() => ({ firstName: firstName })),
updateLastName: (lastName) => set(() => ({ lastName: lastName })),
}))
// In consuming app
function App() {
const firstName = useStore((state) => state.firstName)
const updateFirstName = useStore((state) => state.updateFirstName)
return (
<main>
<label>
First name
<input
// Update the "firstName" state
onChange={(e) => updateFirstName(e.currentTarget.value)}
value={firstName}
/>
</label>
<p>
Hello, <strong>{firstName}!</strong>
</p>
</main>
)
} |
I test it and it's work well. |
Yeah, it would make the example more realistic.
Yes, we avoid using bare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
@dai-shi would you merging this PR please? |
You forgot to run Prettier and the build pipeline fails. execute: |
I ran it locally, but it didn't change anything in my code. |
Are you sure? Unless you have special configs or environments, |
No, changing more than one file is unexpected. |
So what do I need to do? |
I can probably do it for you. But, as I have never heard of it, I'm very curious how your configuration causes it so. Anything you notice? Do you have prettier config somewhere? |
I just have the Prettier extension, I don't know about another config about that |
Hm? Can you run the command without your IDE? |
I tried it without my IDE, it's doesn't matter the response as the same as when I ran this in IDE |
Can you try removing |
I ran it but it didn't happening So do you want I to try more something? |
Yeah, because unless we solve this, you will not be able to contribute to the project next time, and the same thing could happen to other developers. What's the result of |
Interesting. I have no idea why What about cloning a repo separately and run |
It seems that you, @OshriAsulin are using Windows. My working theory is that Prettier changed line endings from CRLF to LF, when it changed more than 1 file. and https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration (look for |
package.json
Outdated
@@ -163,6 +163,7 @@ | |||
"@types/use-sync-external-store": "^0.0.3", | |||
"@typescript-eslint/eslint-plugin": "^6.2.1", | |||
"@typescript-eslint/parser": "^6.2.1", | |||
"@veake/prettier-config": "^1.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused and sorry if things confuse you.
I'd expect this PR to change only one file in docs.
change just two files as you wrote
Did we say to change package.json and yarn.lock files? Sorry for taking your time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good, I'm also confused...
So please you can explain to me from the start again what is all the changes that you expect them?
I ran the command yarn add prettier
as you mentioned, and now it has changed just two files instead of a lot of files as it happened in the last time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is to improve docs.
The target file is docs/guides/updating-state.md
.
What's expected is to change only that file.
af964ff changes three files compared to main
branch.
I don't know what's wrong as usually we don't have such a problem.
If you don't have LF issues, I think reverting the last commit and running yarn
and yarn run prettier
should change only one file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OshriAsulin Check if you are running yarn run prettier
, not yarn add prettier
.
The add
command will install new packages, that is not what you want here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sewera
As you can see yarn run prettier
also didn't help because he modified a lot of files, I really don't understand why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is to improve docs. The target file is
docs/guides/updating-state.md
. What's expected is to change only that file. af964ff changes three files compared tomain
branch.I don't know what's wrong as usually we don't have such a problem. If you don't have LF issues, I think reverting the last commit and running
yarn
andyarn run prettier
should change only one file.
I fixed all the commits to one commit, but I didn't success in running the prettier command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't help because he modified a lot of files
It looks like CRLF/LF difference issue as pointed out.
af964ff
to
12a8357
Compare
Merging this for now. Hope you find a solution to the prettier issue. |
I hope I can find a solution to this. Could you explain what exactly the |
And I have more two questions- |
I found more places this issue is exist can I work on this issue? |
Feel free to open PRs to improve docs. If you think something should be discussed in advance, you can open a new discussion. The first goal is just run prettier without any changes, and it shouldn't change anything. git clone https://github.com/pmndrs/zustand.git
cd zustand
yarn
yarn run prettier |
https://github.com/pmndrs/zustand/pulse https://github.com/pmndrs/zustand/graphs/contributors will show top 100 contributors. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [zustand](https://github.com/pmndrs/zustand) | [`4.4.1` -> `4.4.6`](https://renovatebot.com/diffs/npm/zustand/4.4.1/4.4.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/zustand/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/zustand/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/zustand/4.4.1/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/zustand/4.4.1/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pmndrs/zustand (zustand)</summary> ### [`v4.4.6`](https://github.com/pmndrs/zustand/releases/tag/v4.4.6) [Compare Source](https://github.com/pmndrs/zustand/compare/v4.4.5...v4.4.6) v4.4.5 has an issue with some TypeScript configs about module resolution. It should be fixed now. Thanks for the patience. #### What's Changed - Update export types by [@​dbritto-dev](https://github.com/dbritto-dev) in [https://github.com/pmndrs/zustand/pull/2170](https://github.com/pmndrs/zustand/pull/2170) #### New Contributors - [@​cheatkey](https://github.com/cheatkey) made their first contribution in [https://github.com/pmndrs/zustand/pull/2147](https://github.com/pmndrs/zustand/pull/2147) - [@​frixaco](https://github.com/frixaco) made their first contribution in [https://github.com/pmndrs/zustand/pull/2166](https://github.com/pmndrs/zustand/pull/2166) **Full Changelog**: pmndrs/zustand@v4.4.5...v4.4.6 ### [`v4.4.5`](https://github.com/pmndrs/zustand/releases/tag/v4.4.5) [Compare Source](https://github.com/pmndrs/zustand/compare/v4.4.4...v4.4.5) Hopefully, it should fix some issues with Node.js environment including Next.js. #### What's Changed - fix: importing CJS React in ESM by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/zustand/pull/2154](https://github.com/pmndrs/zustand/pull/2154) - Apply publint recommendations by [@​dbritto-dev](https://github.com/dbritto-dev) in [https://github.com/pmndrs/zustand/pull/2157](https://github.com/pmndrs/zustand/pull/2157) #### New Contributors - [@​plrs9816](https://github.com/plrs9816) made their first contribution in [https://github.com/pmndrs/zustand/pull/2137](https://github.com/pmndrs/zustand/pull/2137) - [@​Brammm](https://github.com/Brammm) made their first contribution in [https://github.com/pmndrs/zustand/pull/2139](https://github.com/pmndrs/zustand/pull/2139) - [@​sobies93](https://github.com/sobies93) made their first contribution in [https://github.com/pmndrs/zustand/pull/2142](https://github.com/pmndrs/zustand/pull/2142) **Full Changelog**: pmndrs/zustand@v4.4.4...v4.4.5 ### [`v4.4.4`](https://github.com/pmndrs/zustand/releases/tag/v4.4.4) [Compare Source](https://github.com/pmndrs/zustand/compare/v4.4.3...v4.4.4) There was a tiny issue in v4.4.3, which broke with some bundlers, which this version fixes. #### What's Changed - fix(build): patch entry points zustand/shallow for CJS by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/zustand/pull/2128](https://github.com/pmndrs/zustand/pull/2128) **Full Changelog**: pmndrs/zustand@v4.4.3...v4.4.4 ### [`v4.4.3`](https://github.com/pmndrs/zustand/releases/tag/v4.4.3) [Compare Source](https://github.com/pmndrs/zustand/compare/v4.4.2...v4.4.3) The changes in v4.4.2 were troublesome for some users. This version should fix/mitigate such cases. #### What's Changed - fix(shallow): Extract shallow vanilla and react by [@​dbritto-dev](https://github.com/dbritto-dev) in [https://github.com/pmndrs/zustand/pull/2097](https://github.com/pmndrs/zustand/pull/2097) - fix(types): mitigate devtools typing by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/zustand/pull/2099](https://github.com/pmndrs/zustand/pull/2099) **Full Changelog**: pmndrs/zustand@v4.4.2...v4.4.3 ### [`v4.4.2`](https://github.com/pmndrs/zustand/releases/tag/v4.4.2) [Compare Source](https://github.com/pmndrs/zustand/compare/v4.4.1...v4.4.2) This adds `useShallow` hook to cover some use cases that are deprecated with v4.4.0 change. Check out [the guide](https://github.com/pmndrs/zustand/blob/ec538e9d4c0b9b5759e6dfd0fd3c9a21f8236949/docs/guides/prevent-rerenders-with-use-shallow.md). ##### Migration Guide [#​1991](https://github.com/pmndrs/zustand/issues/1991) requires something like below if you are using the `devtools` middleware *and* TypeScript. ```diff import { devtools } from 'zustand/middleware' + import type {} from '@​redux-devtools/extension' ``` ##### What's Changed - fix(types)(middleware/devtools): avoid copying types by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/zustand/pull/1991](https://github.com/pmndrs/zustand/pull/1991) - fix(traditional): make defaultEqualityFn optional in TS Types by [@​charkour](https://github.com/charkour) in [https://github.com/pmndrs/zustand/pull/2060](https://github.com/pmndrs/zustand/pull/2060) - feat: add useShallow by [@​FaberVitale](https://github.com/FaberVitale) in [https://github.com/pmndrs/zustand/pull/2090](https://github.com/pmndrs/zustand/pull/2090) ##### New Contributors - [@​aykutkardas](https://github.com/aykutkardas) made their first contribution in [https://github.com/pmndrs/zustand/pull/1993](https://github.com/pmndrs/zustand/pull/1993) - [@​michelts](https://github.com/michelts) made their first contribution in [https://github.com/pmndrs/zustand/pull/1997](https://github.com/pmndrs/zustand/pull/1997) - [@​elusive](https://github.com/elusive) made their first contribution in [https://github.com/pmndrs/zustand/pull/2001](https://github.com/pmndrs/zustand/pull/2001) - [@​mayank1513](https://github.com/mayank1513) made their first contribution in [https://github.com/pmndrs/zustand/pull/2015](https://github.com/pmndrs/zustand/pull/2015) - [@​fdb](https://github.com/fdb) made their first contribution in [https://github.com/pmndrs/zustand/pull/2029](https://github.com/pmndrs/zustand/pull/2029) - [@​tmkx](https://github.com/tmkx) made their first contribution in [https://github.com/pmndrs/zustand/pull/2032](https://github.com/pmndrs/zustand/pull/2032) - [@​OshriAsulin](https://github.com/OshriAsulin) made their first contribution in [https://github.com/pmndrs/zustand/pull/2028](https://github.com/pmndrs/zustand/pull/2028) - [@​ivanquirino](https://github.com/ivanquirino) made their first contribution in [https://github.com/pmndrs/zustand/pull/2047](https://github.com/pmndrs/zustand/pull/2047) - [@​stavkamil](https://github.com/stavkamil) made their first contribution in [https://github.com/pmndrs/zustand/pull/2071](https://github.com/pmndrs/zustand/pull/2071) - [@​NaamuKim](https://github.com/NaamuKim) made their first contribution in [https://github.com/pmndrs/zustand/pull/2088](https://github.com/pmndrs/zustand/pull/2088) - [@​FaberVitale](https://github.com/FaberVitale) made their first contribution in [https://github.com/pmndrs/zustand/pull/2090](https://github.com/pmndrs/zustand/pull/2090) **Full Changelog**: pmndrs/zustand@v4.4.1...v4.4.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 4pm every weekday" in timezone Europe/Paris, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/specfy/specfy). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6ImNob3JlL3Jlbm92YXRlQmFzZUJyYW5jaCJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Description:
This pull request adds import statements to the project's documentation to illustrate how to use the create and shallow functions from the zustand library.
Changes Made:
Added import statement for create from 'zustand'.
Added import statement for shallow from 'zustand/shallow'.
This pr addresses to issue #2024
The script is top before the changes- https://docs.pmnd.rs/zustand/guides/updating-state
Screenshots:
After my changes-