Hello everyone,
Gio is awesome. I've been developing tools based on gio. However I
found that the way I organize codes with gio is somehow exhausting
compared to modern web development routine.
Is there any possibilty that gio codes could be organized in the
following react-liked way?
```
func main() {
win := Component(func(props struct{}, children ...func() Node) Node {
counter, setCounter := UseState(0)
doubled, setDoubled := UseState(0)
handleClick := UseCallback(func() {
setCounter(counter + 1)
}, []any{counter})
UseEffect(func() func() {
setDoubled(counter * 2)
return nil // or return func() {}
}, []any{counter})
if counter >= 4 {
return nil // closes the window
}
if counter >= 3 {
go func() {
<-time.NewTimer(time.Second * 3).C
setCounter(4)
}()
return widgets.Label(widgets.LabelProps{Text: "Close
window in 3 seconds"})
}
return widgets.List(widgets.ListProps{},
func() Node { return
widgets.Label(widgets.LabelProps{Text: fmt.Sprintf("counter: %d",
counter)}) },
func() Node { return
widgets.Label(widgets.LabelProps{Text: fmt.Sprintf("doubled: %d",
doubled)}) },
func() Node { return
widgets.Button(widgets.ButtonProps{OnClick: handleClick}) },
)
})
go WindowRender(win)
go WindowRender(win)
app.Main() // app would quit after both windows are closed
}
```
It doesn't have to be react-liked at all. Other frameworks like vue
are also good. I've tried to create a middle layer to let the codes
above work but not too much progress yet.
If anyone is interested, let me know please. Also any guidance would
be appreciated.
--
Wenhua Shi
On Tue, Jun 4, 2024 at 1:05 PM Wenhua Shi <march511@gmail.com> wrote:
>
> Hello everyone,
>
> Gio is awesome. I've been developing tools based on gio. However I
> found that the way I organize codes with gio is somehow exhausting
> compared to modern web development routine.
It seems like you're looking for "declarative UI". This is *possible*
atop Gio, but not provided or implemented by any public package I'm
aware of. Such UI paradigms hide the details of building and
maintaining the state of widgets/layouts. You can definitely build it
if you're so inclined.
Cheers,
Chris