megahertz / react-simple-wysiwyg

Simple and lightweight React WYSIWYG editor
https://megahertz.github.io/react-simple-wysiwyg/
MIT License
119 stars 21 forks source link

Uncaught TypeError: Cannot read properties of null (reading 'htmlMode') #14

Closed Velkuss89 closed 1 year ago

Velkuss89 commented 1 year ago

Hello everyone,

Thank you for great work, it's really useful component. I have some problem after updating react to latest version, so I am not sure if this is right place to ask a question, but here we go

Here is my Editor control ...

<div style={{ width: width }} className={`${error && (!valueStripped || valueStripped === '') ? classes.errorExists : ''}`}>
                    <Editor value={value} onChange={onChange} disabled={disabled}
                        className={className ?? classes.editorControl}
                        required={required} placeholder={placeholderValue} >
                        <Toolbar>
                            <BtnUndo />
                            <BtnRedo />
                            {!disabled && noLink !== 1 ? <BtnLink /> : <></>}
                            {
                                showExtraInfo ?
                                    <>
                                        <p variant="caption" className={placeholderColor ?? classes.info}> {`${placeholderValue} ${entity ?? ''} *`} </p>
                                        <p variant="caption" className={charCounterColor ?? classes.charCounter}>{`${valueStripped?.length === undefined ? 0 : valueStripped?.length}/${maxChars}`}</p>
                                    </> : <></>
                            }
                        </Toolbar>
                    </Editor>
                </div>

but on page load, after update of react i keep getting error in this function

function onTextSelect(event: SyntheticEvent<HTMLElement>) {
    onSelect?.(event);
    editorState.update({ $selection: getSelectedNode() });
  }

Cannot read properties of null (reading 'htmlMode') at Editor (Editor.tsx:31:1)

Is this something you could help me with?

Thank you

megahertz commented 1 year ago

Thank you for the report, I'll try investigate that on this week.

megahertz commented 1 year ago

I've added an example in README. You need to wrap the Editor by EditorProvider

Velkuss89 commented 1 year ago

That fixed it, no error anymore, thank you!