Files
outline/app/editor/components/NodeViewRenderer.tsx
codegen-sh[bot] e978f63217 Fix React 18 implicit children types with codemod
- Applied types-react-codemod implicit-children transform
- Updated 63 components to use React.PropsWithChildren
- Fixed React.FC types to be compatible with React 18
- Ensures proper typing for components that accept children props

This addresses React 18's removal of implicit children from component props.
2025-06-29 10:12:31 +00:00

34 lines
778 B
TypeScript

import isEqual from "lodash/isEqual";
import { action, computed, observable } from "mobx";
import { FunctionComponent } from "react";
import { createPortal } from "react-dom";
export class NodeViewRenderer<T extends object> {
@observable public props: T;
public constructor(
public element: HTMLElement,
private Component: FunctionComponent<React.PropsWithChildren<unknown>>,
props: T
) {
this.props = props;
}
@computed
public get content() {
return createPortal(<this.Component {...this.props} />, this.element);
}
@action
public updateProps(props: T) {
if (!isEqual(props, this.props)) {
this.props = props;
}
}
@action
public setProp<K extends keyof T>(key: K, value: T[K]) {
this.props[key] = value;
}
}