Fix renderComponent
Some checks failed
Lint / lint (push) Failing after 8s

This commit is contained in:
Julien Valverdé
2025-12-29 18:33:38 +01:00
parent 2398118105
commit 7032432e74
2 changed files with 20 additions and 5 deletions

View File

@@ -6,6 +6,6 @@ import { TestUi1Component } from "./TestUi1Component"
export default class TestUi1 extends Control { export default class TestUi1 extends Control {
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
_ready(): void { _ready(): void {
Renderer.render(React.createElement(TestUi1Component), this) Renderer.renderComponent(this, TestUi1Component)
} }
} }

View File

@@ -1,10 +1,26 @@
/** biome-ignore-all lint/complexity/noBannedTypes: {} is the "empty props" type in React */
import type { Node, NodePathMap } from "godot" import type { Node, NodePathMap } from "godot"
import * as React from "react"
import * as Reconciler from "./Reconciler.js" import * as Reconciler from "./Reconciler.js"
const ConcurrentRoot = 1 const ConcurrentRoot = 1
export const render = (element: React.ReactNode, container: Node<NodePathMap>, callback?: () => void): number => { export const renderComponent: {
(
container: Node<NodePathMap>,
component: React.FC<{}>,
): void
<P>(
container: Node<NodePathMap>,
component: React.FC<P>,
props: NoInfer<P>,
): void
} = (
container: Node<NodePathMap>,
component: React.FC<{}>,
props?: Record<string, unknown>,
): void => {
const reconciler = Reconciler.make() const reconciler = Reconciler.make()
if (!(container as any)._rootContainer) if (!(container as any)._rootContainer)
@@ -18,10 +34,9 @@ export const render = (element: React.ReactNode, container: Node<NodePathMap>, c
console.error, console.error,
) )
return reconciler.updateContainer( reconciler.updateContainer(
element, React.createElement(component, props),
(container as any)._rootContainer, (container as any)._rootContainer,
null, null,
callback,
) )
} }