Add useSignal
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2026-01-01 23:25:05 +01:00
parent d37c5e1405
commit fae11b2024
8 changed files with 73 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
import Godot, { Vector2 } from "godot"
import { useEffect, useState } from "react"
import { useState } from "react"
import { Component } from "react-godot-renderer"
@@ -11,26 +11,16 @@ const Button = Component.make(Godot.Button)
export function TestUi1Component() {
const [text, setText] = useState("Default text")
const textEditRef = TextEdit.useUnsafeRef()
const buttonRef = Button.useUnsafeRef()
const textEditRef = TextEdit.useRef()
Component.useSignal(textEditRef, "text_changed", function(this) {
setText(this.text)
})
useEffect(() => {
const onTextChanged = Godot.Callable.create(() => {
setText(textEditRef.current.text)
})
const buttonRef = Button.useRef()
Component.useSignal(buttonRef, "pressed", () => {
console.log("Pressed!")
})
textEditRef.current.text_changed.connect(onTextChanged)
return () => { textEditRef.current.text_changed.disconnect(onTextChanged) }
}, [textEditRef.current])
useEffect(() => {
const onPressed = Godot.Callable.create(() => {
console.log("Pressed!")
})
buttonRef.current.pressed.connect(onPressed)
return () => { buttonRef.current.pressed.disconnect(onPressed) }
}, [buttonRef.current])
return (
<HFlowContainer