Skip to content

docs: created the new TypeScript Beginner Guide#3246

Merged
dai-shi merged 21 commits intopmndrs:mainfrom
yuraBezh:docs/typescript-beginner-guide
Oct 31, 2025
Merged

docs: created the new TypeScript Beginner Guide#3246
dai-shi merged 21 commits intopmndrs:mainfrom
yuraBezh:docs/typescript-beginner-guide

Conversation

@yuraBezh
Copy link
Copy Markdown
Contributor

@yuraBezh yuraBezh commented Oct 2, 2025

Summary

Created the new TypeScript Beginner Guide. This is the result of the previous PR discussions

Check List

  • pnpm run fix for formatting and linting code and docs

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
zustand-demo Ready Ready Preview Comment Oct 31, 2025 4:29am

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Oct 2, 2025

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Oct 12, 2025

demostarter

npm i https://pkg.pr.new/zustand@3246

commit: 94d36e7

}

// Create store with explicit generic <BearState>
export const useBearStore = create<BearState>((set) => ({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't TypeScript guide (for beginner or not) show create<T>()(...) usage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, that’s a valid point. Added this part

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should always tell create<T>()(...) for beginners. create<T>(...) works for some cases, but it's for advanced users.

Copy link
Copy Markdown
Contributor Author

@yuraBezh yuraBezh Oct 16, 2025

Choose a reason for hiding this comment

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

@dai-shi I switched to create()(...). Also updated examples to make them more consistent. Could you please take a look?

Comment on lines +60 to +64
// Fix the type with create<BearState>()
const createBearStore = create<BearState>()

// Initialize the store separately
export const useBearStore = createBearStore((set) => ({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't recommend separating this. The extra parens () only exists because of TS limitation.

Please stick with create<T>()(...) pattern throughout the guide.

Suggested change
// Fix the type with create<BearState>()
const createBearStore = create<BearState>()
// Initialize the store separately
export const useBearStore = createBearStore((set) => ({
export const useBearStore = create<BearState>()((set) => ({

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it. Fixed

Copy link
Copy Markdown
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.

Sorry for the delay. Thanks for your patience.

Comment on lines +174 to +176
type BearState = ExtractState<typeof useBearStore>
// or
type BearSnapshot = ReturnType<typeof useBearStore.getState>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we only show the first method? Isn't it enough for beginners?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, let's make it more straightforward

Comment on lines +315 to +317
const bearStoreCreator = devtools(bearCreator)

export const useBearStore = create<BearState>()(bearStoreCreator)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't prefer this separation either. Let's suggest create<T>()(devtools(...)) pattern in the guide for all middleware.

Copy link
Copy Markdown
Contributor Author

@yuraBezh yuraBezh Oct 18, 2025

Choose a reason for hiding this comment

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

@dai-shi Sure!
I unified the view of the middleware usage with create<T>()(devtools(...)) pattern and without redundant store creators. Please review.

@yuraBezh
Copy link
Copy Markdown
Contributor Author

@dbritto-dev @dai-shi
Thank you for the feedback.
I’ve removed the "Hooks" section and added API documentation links.

@dbritto-dev
Copy link
Copy Markdown
Collaborator

@yuraBezh thanks, I'd to improve the troubleshooting section in those docs but I need gather some cases from discussions first hehe

@yuraBezh
Copy link
Copy Markdown
Contributor Author

@yuraBezh thanks, I'd to improve the troubleshooting section in those docs but I need gather some cases from discussions first hehe

@dbritto-dev @dai-shi
Is there anything else I should do for this PR, or are we good?
If the Troubleshooting section isn’t ready yet, I can remove the last commit with related links for now and open a small PR with links once Troubleshooting is finalized.

BTW, I see some failing checks - not sure if they’re related to the PR changes or not. All tests passed locally.

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 31, 2025

I'm waiting for @dbritto-dev review.

Not sure about CI either. Maybe if we retrigger it, it may pass.

Copy link
Copy Markdown
Collaborator

@dbritto-dev dbritto-dev left a comment

Choose a reason for hiding this comment

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

LGTM

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 31, 2025

Not sure about CI either. Maybe if we retrigger it, it may pass.

Maybe it doesn't. Not sure how it happens. We need to figure it out.

@dbritto-dev
Copy link
Copy Markdown
Collaborator

@dai-shi could it be @redux-devtools/extension?

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Oct 31, 2025

@dai-shi could it be @redux-devtools/extension?

Seems like it's due to the node version. In CI, the lts version is automatically picked.

Copy link
Copy Markdown
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.

LGTM

// In components, you can use both stores safely
function MultipleSelectors() {
const { bears, food } = useBearStore(
useShallow((state) => ({ bears: state.bears, food: state.food }))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By the way, we could also do this.

const [bears, food] = useBearStore(useShallow((s) => [s.bears, s.food]));

I guess people like objects over arrays.

@dai-shi dai-shi merged commit d0c71ce into pmndrs:main Oct 31, 2025
32 checks passed
@yuraBezh yuraBezh deleted the docs/typescript-beginner-guide branch October 31, 2025 04:32
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.

3 participants