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

fix: toggling AppDetailNav causes unnecessary component rerenders #3718

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

yikayiyo
Copy link
Contributor

Description

When a state selector is not set, the component will render on every state change. Even if only extracting a specific state field using object destructuring, it will still respond to all state changes. This will cause some unnecessary component rerenders.

// no
const state = useAppStore()
// no
const { appDetail } = useAppStore()
// yes
const appDetail = useAppStore(state => state.appDetail)

create or createStore

The store created with create doesn't require context providers. In some cases, you may want to use contexts for dependency injection or if you want to initialize your store with props from a component. Because the normal store is a hook, passing it as a normal context value may violate the rules of hooks.

Type of Change

  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. ☕️ typescript Pull request that update TypeScript code. 💪 enhancement New feature or request labels Apr 23, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 24, 2024
@JzoNgKVO JzoNgKVO merged commit 40e36e9 into langgenius:main Apr 24, 2024
8 checks passed
@yikayiyo yikayiyo deleted the fix-useStore-rerender branch May 3, 2024 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files. ☕️ typescript Pull request that update TypeScript code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants