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

Use React context for controlled CommentsProvider values #2760

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

12joan
Copy link
Collaborator

@12joan 12joan commented Nov 23, 2023

Description

See changesets.

    <CommentsProvider
      initialComments={commentsData}
      users={usersData}
      myUserId="1"
    >
      {children}
    </CommentsProvider>

@12joan 12joan requested a review from zbeyens November 23, 2023 15:42
Copy link

changeset-bot bot commented Nov 23, 2023

🦋 Changeset detected

Latest commit: c6fffba

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

This PR includes changesets to release 2 packages
Name Type
@udecode/plate-comments Major
@udecode/plate Major

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

Copy link

vercel bot commented Nov 23, 2023

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

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2023 3:51pm

@reviewpad reviewpad bot added the medium Pull request is medium label Nov 23, 2023
onCommentUpdate: null,
onCommentDelete: null,
} as CommentsStoreState,
} satisfies CommentsStoreState as CommentsStoreState,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This combined syntax defers to TypeScript to typecheck the initial values, while also preserving the type information from CommentsStoreState.

Only as: Disable's TypeScript's ability to detect type errors in the initial value

Only satisfies: Does not apply the CommentsStoreState type to the resulting expression.


const storeGetters = useCommentsStore().get;

// Combine getters from context and store
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If this combination of classic context and jōtai becomes a common pattern in the future, we could add a set of helpers for this.

@zbeyens zbeyens merged commit 77f24d4 into main Nov 23, 2023
7 checks passed
@zbeyens zbeyens deleted the feat/comments-provider-refactor branch November 23, 2023 19:39
@zbeyens zbeyens mentioned this pull request Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium Pull request is medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants