uiwjs / uiwjs/react-codemirror

Using React component in decorations

Open
#398 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

Is there a known solution for using a React component in a widget decoration?

I initially thought that I could perhaps use a Portal, where it queried the CodeMirror editor after render and then replaced an empty widget with my component, like:

const Code = () => {
  const cmRef = React.useRef<ReactCodeMirrorRef>({});

  return (
    <>
      <CodeMirror ref={cmRef} />

      <WidgetPortal {...{ cmRef }}>
        <Widget />
      </WidgetPortal>
    </>
  );
};

const WidgetPortal = ({
  children,
  cmRef,
}: {
  children: React.ReactNode;
  cmRef: React.MutableRefObject<ReactCodeMirrorRef>;
}) => {
  const targetEl = cmRef.current?.editor?.querySelector(".widget");
  return targetEl ? ReactDOM.createPortal(children, targetEl) : null;
};

But this doesn't seem to work - no errors are thrown and the empty widget container is still in the DOM so I assume the CodeMirror component is rendering in a way that is preventing my portal from mounting.

Is there any other way you think this could be achieved?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the widget decoration reference and the React Portal example linked in the issue, then inspect the CodeMirror editor ref used by the React component. Determine whether React content can be mounted into a decoration widget without leaving the empty container, and document or demonstrate a working approach when the behavior is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.