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

feat(stash): add useStash and improve other helpers #3320

Merged
merged 8 commits into from
Oct 24, 2024
Merged

Conversation

holic
Copy link
Member

@holic holic commented Oct 22, 2024

No description provided.

Copy link

changeset-bot bot commented Oct 22, 2024

🦋 Changeset detected

Latest commit: 08c6d7a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@latticexyz/stash Patch
@latticexyz/store-sync Patch
@latticexyz/dev-tools Patch
@latticexyz/explorer Patch
@latticexyz/store-indexer Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/cli Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/protocol-parser Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/store Patch
@latticexyz/utils Patch
@latticexyz/world-module-erc20 Patch
@latticexyz/world-module-metadata Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@holic holic changed the title feat(stash): add useStore and improve other helpers feat(stash): add useStash and improve other helpers Oct 22, 2024
export type GetRecordArgs<
table extends Table = Table,
defaultValue extends Omit<TableRecord<table>, keyof Key<table>> | undefined = undefined,
> = propwiseXor<{ stash: Stash }, { state: 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 you think it's still useful to have both variants (with stash or with state) or should we just change all actions to take in state for simplicity?

Copy link
Member Author

@holic holic Oct 22, 2024

Choose a reason for hiding this comment

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

For these two actions, I think it's useful to have both and not much work to maintain both.

The other actions don't make as much sense, like setRecords needs to have the original stash to mutate state + notify.

Are there other actions that could benefit from having a state variant?

Copy link
Member Author

@holic holic Oct 22, 2024

Choose a reason for hiding this comment

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

Another thing on my mind is that we'll likely have a corresponding useRecord and useRecords hooks to mirror the state variant of getRecord and getRecords as shorthands for common usage in the React context:

useStash(stash, (state) => getRecord({ state, table, key })
// to
useRecord({ stash, table, key })

The nice things about building with useRecord and useRecords hooks instead of useStash directly is that you avoid the foot gun that is infinite rendering due to unstable return values of a selector without also specifying an equality function - this can all be abstracted away.

@holic holic merged commit 93d0e76 into main Oct 24, 2024
13 checks passed
@holic holic deleted the holic/stash-helpers branch October 24, 2024 21:23
@holic holic mentioned this pull request Oct 24, 2024
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.

2 participants