When I started building Retui, I had one goal: make terminal application development feel simple and enjoyable.
As a developer, I have worked with many UI frameworks over the years. One thing I always liked about React was its Hooks. They made it easy to manage state and keep components clean. I wanted to bring the same experience to terminal applications written in Go.
A Familiar Way to Build
Many developers already know how React Hooks work.
Instead of asking them to learn a completely new programming model, Retui lets them write components in a familiar way.
go
func Counter() retui.Element {
count, setCount := retui.UseState(0)
return components.Button().
Label(fmt.Sprintf("Count: %d", count)).
OnClick(func() {
setCount(count + 1)
})
}
The code is easy to read. The state stays close to the UI, making it much easier to understand.
Less Boilerplate
Without hooks, even a small component often needs extra structs, initialization code, and methods just to store a few values.
With hooks, I can write the logic in a single function.
That means less code, fewer files, and less time spent switching between different parts of the project.
State Belongs to the Component
Every component should manage its own state whenever possible.
A text input should know its current value. A checkbox should know whether it is checked. A dialog should know whether it is open.
Hooks make this natural. Each component owns its own state without requiring a large global state manager.
Where the State Actually Lives
Here is the part I go back and forth on the most.
In React, hook state is attached to the component instance itself. Retui does not work that way. Underneath the API, state is kept in one shared store, and each call to UseState gets its own slot based on the order hooks are called in.
This was not the plan from day one. I first tried to copy React's approach and attach state to each component instance. It worked, but it meant building something close to a reconciler just to track which instance was which. That was a lot of machinery for a young framework with a small render loop, so I stepped back and went simpler.
The trade-off is real, and I want to be upfront about it. Because state lives in one shared place, calling the same component twice without a unique key can cause two instances to read and write the same slot. React avoids this because the tree structure gives every instance its own identity for free. Retui does not have that, so the developer has to be a bit more careful, especially with lists of repeated components.
For that case, Retui has UseStateKeyed, which stores state by a string key instead of call order. It is less automatic, but it is honest about how the state is stored, and it has kept the internals small enough that I can still debug the whole thing in one sitting.
Easier to Reuse
Hooks also encourage small, reusable components.
Instead of creating one large screen with hundreds of lines of code, I can split it into many small components, each with its own state and logic.
Smaller components are easier to test, maintain, and reuse in other projects.
Side Effects Are Clear
Sometimes a component needs to perform an action after rendering.
For example:
Load data
Start a timer
Listen for keyboard events
Clean up resources
UseEffect keeps this logic separate from the UI itself, making the component much easier to follow.
It Feels Natural
One of my goals with Retui is to make developers focus on building applications instead of worrying about framework code.
When I write a Retui component, I want it to feel like writing a normal Go function.
Hooks help achieve that.
Is Retui Trying to Copy React?
Not exactly.
Retui is written in Go, not JavaScript.
The rendering system, terminal handling, and internal architecture are completely different.
What I borrowed is the developer experience.
React Hooks solved a real problem, and I believe the idea works just as well for terminal applications.
Final Thoughts
I didn't add hooks because they are popular.
I added them because they make code simpler.
They reduce boilerplate, keep state close to the UI, encourage reusable components, and make applications easier to maintain.
If you've used React before, Retui will feel familiar.
If you haven't, you'll probably find that hooks are simply a clean and practical way to build terminal applications.
Retui is open source. If you want to see how the hooks system is built, or you disagree with a decision I made, the code is on GitHub: github.com/subhasundardass/retui.
Top comments (0)