Skip to content

Setting reactive value within component #402

Description

@kerrycobb

Is this the most idiomatic way of doing things? The part I'm perplexed by is self.text->set().

import happyx

component InputComponent:
  text: State[string]
  html:
    tDiv:
      "Input: "
      tInput(type="text", value="{self.text}"):
        @input(event):
          self.text->set($event.target.value)

var text = remember "Test"
appRoutes("app"):
  "/":
    component InputComponent(text=text)

It is not a logical step from this for me.

import happyx
var text = remember "Test"
appRoutes("app"):
  "/":
    tDiv:
      "Input: "
      tInput(type="text", value="{text}"):
        @input(event):
          text.set($event.target.value)

I assumed you would want to have self.text.set.

But it is the only way I could come up with that works. Adding an example like this or a better approach to the docs somewhere might be valuable as it took me a lot of trial and error and finally the help of an LLM to reach this point.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions