Skip to content

Commit 60df379

Browse files
committed
fix: improve types for rendered components props for ReactRenderer
1 parent 8df5b50 commit 60df379

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/new-rabbits-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tiptap/react': patch
3+
---
4+
5+
Improve typings for rendered component props in ReactRenderer.

packages/react/src/ReactRenderer.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function isReact19Plus(): boolean {
9898
return false
9999
}
100100

101-
export interface ReactRendererOptions {
101+
export interface ReactRendererOptions<P extends Record<string, any> = object> {
102102
/**
103103
* The editor instance.
104104
* @type {Editor}
@@ -110,7 +110,7 @@ export interface ReactRendererOptions {
110110
* @type {Record<string, any>}
111111
* @default {}
112112
*/
113-
props?: Record<string, any>
113+
props?: P
114114

115115
/**
116116
* The tag name of the element.
@@ -164,12 +164,12 @@ export class ReactRenderer<R = unknown, P extends Record<string, any> = object>
164164
*/
165165
constructor(
166166
component: ComponentType<R, P>,
167-
{ editor, props = {}, as = 'div', className = '' }: ReactRendererOptions,
167+
{ editor, props, as = 'div', className = '' }: ReactRendererOptions<Omit<P, 'ref'>>,
168168
) {
169169
this.id = Math.floor(Math.random() * 0xffffffff).toString()
170170
this.component = component
171171
this.editor = editor as EditorWithContentComponent
172-
this.props = props as P
172+
this.props = (props ?? {}) as P
173173
this.element = document.createElement(as)
174174
this.element.classList.add('react-renderer')
175175

@@ -226,7 +226,7 @@ export class ReactRenderer<R = unknown, P extends Record<string, any> = object>
226226
/**
227227
* Re-renders the React component with new props.
228228
*/
229-
updateProps(props: Record<string, any> = {}): void {
229+
updateProps(props: Partial<Omit<P, 'ref'>> = {}): void {
230230
this.props = {
231231
...this.props,
232232
...props,

0 commit comments

Comments
 (0)