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

Update docs content #2508

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft

Conversation

dbritto-dev
Copy link
Collaborator

Summary

Updating docs content

Check List

  • yarn run prettier for formatting code and docs

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zustand-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 4:39pm

Copy link

codesandbox-ci bot commented Apr 24, 2024

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.

@sewera
Copy link
Collaborator

sewera commented May 2, 2024

I figured you wanted feedback on the structure, not a review, because there are a lot of placeholders there.

I think the structure is fine, the reference section definitely will help. You can consider renaming the learn directory to recipes, because learn suggests a step-by-step guide, a tutorial of some sort in which you can master this library. Something like https://go.dev/learn/ or https://tanstack.com/learn.

The old_docs directory can be renamed to v4 or v4-and-older if you plan to release the new docs together with Zustand v5.

@sewera
Copy link
Collaborator

sewera commented May 2, 2024

I can also strongly recommend any IntelliJ-based IDE for documentation with the Grazie Pro plugin.

I've got IntelliJ IDEA Ultimate, but it also works with Community Edition and I think the new editor, Writerside.

Screenshot 2024-05-02 at 14 54 06

IntelliJ Community Edition and Writerside are free, so you won't have to pay anything. I haven't tested Writerside, so I don't know about its performance.

You can also check out Vale, a command-line tool, albeit with some IDE integrations, but I haven't tested it either.

@dbritto-dev
Copy link
Collaborator Author

dbritto-dev commented May 2, 2024

@sewera what about the structure or the topics? do you have a topic in mind that you would like to see

BTW, I don't like intellij-idea but thanks for the suggestions

@sewera
Copy link
Collaborator

sewera commented May 2, 2024

The structure is good, especially the split between reference and recipes.

One thing I'd do differently is to split it more: recipes, like "Persisting State with Persist Middleware," guides, like "Starting a new project," and reference, like "createWithEqualityFn."

@dbritto-dev
Copy link
Collaborator Author

@sewera btw, I found this tool that use languagetool -> https://marketplace.visualstudio.com/items?itemName=valentjn.vscode-ltex&ssr=false#review-details

@dbritto-dev
Copy link
Collaborator Author

dbritto-dev commented May 2, 2024

I figured you wanted feedback on the structure, not a review, because there are a lot of placeholders there.

I think the structure is fine, the reference section definitely will help. You can consider renaming the learn directory to recipes, because learn suggests a step-by-step guide, a tutorial of some sort in which you can master this library. Something like https://go.dev/learn/ or https://tanstack.com/learn.

The old_docs directory can be renamed to v4 or v4-and-older if you plan to release the new docs together with Zustand v5.

@sewera actually, I'm following React Docs Pattern -> https://react.dev and there would be a tutorial (tic-tac-toe) same as react docs but with zustand

@sewera
Copy link
Collaborator

sewera commented May 2, 2024

Alright, that makes sense. Quick start with tic-tac-toe tutorial and installation are in one section, "Get Started," and recipes are in "Learn React."

That's a good idea to use the React pattern, probably the best in this scenario :)

@dbritto-dev
Copy link
Collaborator Author

@charkour @dai-shi @sewera would you mind reviewing the docs under reference and tell me your thoughts?

`createStore` returns a vanilla store with some API utilities. These API utilities are: `setState`
function, `getState` function, and `subscribe` function.

### `setState` function
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like such functions like setState should be in one place, with hyperlinks to them from, e.g., combine function to avoid copying.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sewera that's not supported with the current setup but when we migrate to vitepress we can move everything in one place and then just import them

@dai-shi dai-shi mentioned this pull request May 22, 2024
15 tasks
@dbritto-dev
Copy link
Collaborator Author

@dai-shi lmk what you think about reference section and documentation, still working on usage and troubleshooting section but apart from that everything else should be done on reference section

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Reviewed the reference docs.

Comment on lines +39 to +40
[`getState` function](#getstate-function) and [`storeApi`](#storeapi) as arguments. It should
return an additional state based on the initial state.
Copy link
Member

Choose a reason for hiding this comment

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

Do we have those for combine?


#### Returns

`combine` returns a new state that is the result of merging the initial state and the additional
Copy link
Member

Choose a reason for hiding this comment

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

More precisely, combine and any other middleware "returns" a state creator.

@@ -0,0 +1,106 @@
---
title: createContext
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this from the reference.

Comment on lines +76 to +77
The `getState` function lets you access to the current state. It can be stale on asynchronous
operations.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if "stale on async operations" is technically correct.

### `createWithEqualityFn` Signature

```ts
createWithEqualityFn<T>()(initializer: StateCreator<T, [], []>, equalityFn: (a: T, b: T) => boolean): UseBoundStore<StoreApi<T>>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
createWithEqualityFn<T>()(initializer: StateCreator<T, [], []>, equalityFn: (a: T, b: T) => boolean): UseBoundStore<StoreApi<T>>
createWithEqualityFn<T>()(initializer: StateCreator<T, [], []>, equalityFn?: (a: T, b: T) => boolean): UseBoundStore<StoreApi<T>>

- `initializer`: The value you want the state to be initially. It can be a value of any type, but
when you pass a function should take `setState` function, `getState` function and `storeApi` as
arguments.
- `equalityFn`: A function that lets you skip re-renders.
Copy link
Member

Choose a reason for hiding this comment

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

it's optional and by default Object.js will be used.

### `combine` Signature

```ts
combine<T, U>(initialState: T, additionalStateCreator: StateCreator<T, [], [], U>): Omit<T, keyof U> & U
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we clarify where we can import this from? combine is from zustand/middleware.


#### Returns

`create` returns a React Hook:
Copy link
Member

Choose a reason for hiding this comment

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

More precisely, it returns a React hook (function) with Store API attached.


# shallow

`shallow` function lets you optimize re-renders.
Copy link
Member

Choose a reason for hiding this comment

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

  • shallow is a comparison function
  • it can be used as a custom equality function to optimize re-renders.


# useShallow ⚛️

`useShallow` is a React Hook lets you memoized a selector function.
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't memoize anything.

Suggested change
`useShallow` is a React Hook lets you memoized a selector function.
`useShallow` is a React Hook that lets you optimize re-renders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants