0

Creating a ref via useRef():

export default function LexicalEditor() {
  const floatingAnchorElem = useRef(null);

  return(
      <LexicalComposer initialConfig={editorConfig} >
        <Container fluid >
          <LexicalToolbarPlugin />
          <Row className="justify-content-xl-center" id="editor-body" >
            <Col xs={7}>
              <div className="editor" ref={floatingAnchorElem}>
                <RichTextPlugin
                  contentEditable={
                    <ContentEditable className="editor-input" style={ { borderColor: 'green', borderStyle: 'solid', minWidth: '50%', width: 'auto', minHeight: 500, height: 'auto' }} />
                  }
                />
              </div>
            </Col>
            <LocalStoragePlugin />
            {floatingAnchorElem.current && (
              <>
                <FloatingLinkEditorPlugin anchorElem={floatingAnchorElem.current} />
              </>
              )
            }
          </Row>
        </Container>
      </LexicalComposer>
  )
}

and then inside FloatingLinkEditorPlugin, creating portal like so:


export function ZiFloatingLinkEditorPlugin(props){
  return(
    createPortal(
        <FloatingLinkEditor editor={activeEditor} anchorElem={props.anchorElem} />,
        props.anchorElem,
      )
)

However, getting this error:

Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref
ZiCode
  • 19
  • 6
  • Are you sure the error is occurring in this component or if you have an old build in your browser? This error typically shows up if you pass a string to `ref` (per https://reactjs.org/link/strict-mode-string-ref). – nico Dec 20 '22 at 05:06

0 Answers0