MCPcopy Create free account
hub / github.com/ckeditor/ckeditor5-react / shouldComponentUpdate

Method shouldComponentUpdate

src/ckeditor.tsx:95–126  ·  view source on GitHub ↗

* The CKEditor component should not be updated by React itself. * However, if the component identifier changes, the whole structure should be created once again.

( nextProps: Readonly<Props<TEditor>> )

Source from the content-addressed store, hash-verified

93 * However, if the component identifier changes, the whole structure should be created once again.
94 */
95 public override shouldComponentUpdate( nextProps: Readonly<Props<TEditor>> ): boolean {
96 const { props, editorSemaphore } = this;
97
98 // Only when the component identifier changes the whole structure should be re-created once again.
99 if ( nextProps.id !== props.id ) {
100 return true;
101 }
102
103 if ( nextProps.disableWatchdog !== props.disableWatchdog ) {
104 return true;
105 }
106
107 if ( editorSemaphore ) {
108 editorSemaphore.runAfterMount( ( { instance } ) => {
109 if ( shouldUpdateEditorData( props, nextProps, instance ) ) {
110 instance.data.set( nextProps.data! );
111 }
112 } );
113
114 if ( 'disabled' in nextProps ) {
115 editorSemaphore.runAfterMount( ( { instance } ) => {
116 if ( nextProps.disabled ) {
117 instance.enableReadOnlyMode( REACT_INTEGRATION_READ_ONLY_LOCK_ID );
118 } else {
119 instance.disableReadOnlyMode( REACT_INTEGRATION_READ_ONLY_LOCK_ID );
120 }
121 } );
122 }
123 }
124
125 return false;
126 }
127
128 /**
129 * Initialize the editor when the component is mounted.

Callers 1

ckeditor.test.tsxFile · 0.80

Calls 5

shouldUpdateEditorDataFunction · 0.85
runAfterMountMethod · 0.80
enableReadOnlyModeMethod · 0.80
disableReadOnlyModeMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected