Skip to content

Conversation

@yuraBezh
Copy link

@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

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 29, 2025 8:17pm

@codesandbox-ci
Copy link

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

pkg-pr-new bot commented Oct 12, 2025

demostarter

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

commit: 271f1db

}

// Create store with explicit generic <BearState>
export const useBearStore = create<BearState>((set) => ({
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 TypeScript guide (for beginner or not) show create<T>()(...) usage?

Copy link
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Collaborator

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

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