Test controlled TextEdit
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2026-01-01 20:26:11 +01:00
parent 84c83c1bef
commit d37c5e1405

View File

@@ -1,5 +1,5 @@
import Godot, { Vector2 } from "godot" import Godot, { Vector2 } from "godot"
import { useEffect } from "react" import { useEffect, useState } from "react"
import { Component } from "react-godot-renderer" import { Component } from "react-godot-renderer"
@@ -9,12 +9,14 @@ const TextEdit = Component.make(Godot.TextEdit)
const Button = Component.make(Godot.Button) const Button = Component.make(Godot.Button)
export function TestUi1Component() { export function TestUi1Component() {
const [text, setText] = useState("Default text")
const textEditRef = TextEdit.useUnsafeRef() const textEditRef = TextEdit.useUnsafeRef()
const buttonRef = Button.useUnsafeRef() const buttonRef = Button.useUnsafeRef()
useEffect(() => { useEffect(() => {
const onTextChanged = Godot.Callable.create(() => { const onTextChanged = Godot.Callable.create(() => {
console.log(textEditRef.current.text) setText(textEditRef.current.text)
}) })
textEditRef.current.text_changed.connect(onTextChanged) textEditRef.current.text_changed.connect(onTextChanged)
@@ -46,7 +48,7 @@ export function TestUi1Component() {
<TextEdit <TextEdit
ref={textEditRef} ref={textEditRef}
name="TextEdit" name="TextEdit"
text="" text={text}
custom_minimum_size={new Vector2(200, 35)} custom_minimum_size={new Vector2(200, 35)}
/> />