Skip to content

prefer-local-portal-component

Prefer a local Portal component over direct createPortal(...) calls.

This rule looks for createPortal calls from @rbxts/react-roblox or react-dom and reports them when the project already has a matching local Portal component.

If the current file already imports that local component, the rule can replace the call with JSX. If the project has no matching local component, or the rule cannot tell which one to use, it does nothing.

Incorrect
import Portal from "../components/portal";
import { createPortal } from "@rbxts/react-roblox";
export function Example(target: Instance) {
return createPortal(<frame />, target);
}
Correct
import Portal from "../components/portal";
export function Example(target: Instance) {
return <Portal target={target}><frame /></Portal>;
}
SourceSupported form
@rbxts/react-robloxcreatePortal(children, target)
react-domcreatePortal(children, container)
react-dom or @rbxts/react-roblox namespace importReactDOM.createPortal(children, target)