Skip to content

Nested components #176

Answered by meowgorithm
alvarogf97 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! Implementing sub-components is super common in Bubble Tea. In fact, all of the packages in Bubbles, the component library, are merely sub-components.

Anyway, your code is more or less on the right track, however you're replacing the entire model in update which is totally doable, however you'll probably find nesting components on your model easier to manage. Here's a hypothetical example of what that could look like:

type model struct {
	// Sub-models
	a tea.Model
	b tea.Model
}

func (m model) Init() tea.Cmd {
	// Initialize sub-models
	return tea.Batch(
		m.a.Init(),
		m.b.Init(),
	)
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	var (
		cmd  tea.Cmd
		cmds []tea.Cmd

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alvarogf97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #175 on December 27, 2021 23:16.