kbrsh / moon

🌙 The minimal & fast library for functional user interfaces
https://moonjs.org
MIT License
6k stars 200 forks source link

Q: Pass data to component? #249

Closed mathiasrw closed 5 years ago

mathiasrw commented 5 years ago

Is it possible to pass data to a component?

Example:

Lets say i have a component displaying a button.

I would like to iterate over a list of words and calling the button component in a way so the button can display the right name.

I guess what i am asking is actually: how can a component access data from the context in which it was "called"

terrybr commented 5 years ago

If you go to the Moon Slack page, Help section, I asked Kabir how to do something very close to what you're asking. https://moonjs.slack.com/messages/C78U8RUCE/ (scroll up and you'll see what I'm asking).

kbrsh commented 5 years ago

Yes, it is possible through arguments. Any data you pass to a component through the attributes in your template are automatically added to its state. See this section in the documentation for more.