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

Add support for uncontrolled ProseMirror component #34

Merged
merged 1 commit into from
Jun 1, 2023

Conversation

smoores-dev
Copy link
Collaborator

Adds a defaultState prop to support uncontrolled usage of the ProseMirror component! This PR ensures that useEditorState always returns an up-to-date EditorState, whether that's from the state prop or from the view state (if uncontrolled)

@smoores-dev smoores-dev requested a review from a team as a code owner June 1, 2023 01:50
@tilgovi
Copy link
Contributor

tilgovi commented Jun 1, 2023

Do we need a separate prop for this or is there a way we can make it sufficient just to not pass dispatchTransaction, similar to how one can just not pass onChange handlers to regular form controls.

@smoores-dev
Copy link
Collaborator Author

I think these are separate, right? For native elements at least, passing onChange doesn't determine controlledness; whether value is undefined does (at least, I'm pretty sure). You might still want/need to hook in to dispatchTransaction to track some kind of state, even if you don't want to lift the whole EditorState

@tilgovi
Copy link
Contributor

tilgovi commented Jun 1, 2023

Your understanding is correct. I'm mistaken. React uses defaultValue and I had no memory of that, if I ever knew it. I think defaultState makes sense.

src/hooks/useEditorView.ts Outdated Show resolved Hide resolved
@smoores-dev smoores-dev merged commit 12d07ee into main Jun 1, 2023
1 check passed
@smoores-dev smoores-dev deleted the default-editor-state branch June 1, 2023 21:28
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.

None yet

2 participants