Corepack chooses package manager to use with the
field `packageManager`. For users using Yarn
through Corepack, this is a real convenience.
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* updated readme with more examples
* moved example to docs from readme
* formatted code with Prettier
---------
Co-authored-by: Ankit Sagar <ankit.sagar@telnesstech.com>
Right now, we're requiring new `StateStorage` implementations to forcefully return `void` from inside `setItem` and `removeItem`.
When using a library that returns the set value for `setItem` or `removeItem`, therefore returning a `string`, it causes Typescript to fail, requiring some weird workarounds.
For example, when using `localforage` (https://github.com/localForage/localForage) one needs to do what we describe below. Notice the `void` keyword.
```typescript
const storage: StateStorage = {
...localForage,
setItem: void localForage.setItem.bind(localForage)
}
```
Another, longer, alternative is
```typescript
const storage: StateStorage = {
...localForage,
// Curly braces are required because we need to "return `void`"
setItem: (name, value) => {
localStorage.setItem(name, value)
}
}
```
By changing the type implementation to ignore types - using unknown - we can simply use `localforage` - and similar libraries - as if we were using `window.localStorage`
* feat(react): implement getServerState by closing over the defaultState
serverState will be used by react on the first client render; this should avoid hydration mismatches when combined with the persist middleware, which can change the state between the SSR and the first CSR
* define getServerState in vanilla.ts
* feat: implement getServerResult in persist middleware
this avoids hydration errors when state is restored from e.g. localstorage synchronously
* feat: capture initialState for getServerState in react
this avoids hydration mismatches when updates happen to the store state between ssr and csr
* refactor: revert changes to oldImpl
* fix: make selector default to identity function
if we default to `api.getState`, we will always read the client snapshot if there is no selector passed. An identity function returns its argument, which is either the snapshot (api.getState) or the server snapshot (api.getServerState)
* define getInitialState in vanilla
* revert WithReact
* fix them
* fix test
* oops, fix another test too
* forgot to use identity
* test: add a test for hydration errors
* fix(readme): imply getInitialState is a public api
---------
Co-authored-by: daishi <daishi@axlight.com>
* Update connect-to-state-with-url-hash.md
Resolved a few errors and type errors in the persist and create state with URL example:
1. createJsonStorage not being called in storageOptions resulting in a type error.
2. Correct hook not being exported
3. Moved the creation of initial state inline to get the correct types passed from create/persist.
4. Used state type as generic for persist.
* yarn prettier run
* Update docs/guides/connect-to-state-with-url-hash.md
Better name for state in setter
Co-authored-by: Danilo Britto <dbritto.dev@gmail.com>
* prettier run
---------
Co-authored-by: Danilo Britto <dbritto.dev@gmail.com>
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* Update third-party-libraries.md
Adding zustand dev tool made by oslabs to the third party libraries.
* Update third-party-libraries.md
changed to alphabetical order
* Update third-party-libraries.md
formatted with prettier/which got rid of the extra space on line 17
* chore(test): update test to stop testing deprecated features
* chore(test): add subscribe test for zustand/vanilla
* chore(test): only verify that subscribe exists on `create`
* chore(test): switch type of test
* fix: unexpected null state update behavior
* chore: lint code
* test: add test for setting state to null
---------
Co-authored-by: wulimao <tao@trlab.com>
* Add a warning to readme about React Server Components
For more information, see https://github.com/pmndrs/zustand/discussions/2200
* Use a softer, more succinct, formally worded warning
---------
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* docs: update documentation of persist
Add superjson serialization/deserialization example to Zustand persist documentation
* docs: fix spelling documentation of persist
* docs: Apply feedback by moving content under custom storage engine and specifying that the code is an example
* docs: Update variable name to example name and separate storage as const