Skip to content

Passing non-string data to dependent child components #14

Answered by kennyfrc
artfulrobot asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @artfulrobot !

What I do in that case is that I use the dot syntax. What that dot essentially does is set a value to a reactive property. Here's an example:

// Instead of this (which would stringify):
html`<my-thing thingData=${this.appData.a}></my-thing>`

// Do this (note the dot before thingData):
html`<my-thing .thingData=${this.appData.a}></my-thing>`

From an example in a real world app I've been working on:

// Simple parent component
class ChatList extends ReactiveElement {
  messages = [
    { id: 1, text: "Hello", type: "user" },
    { id: 2, text: "Hi there!", type: "ai" }
  ];

  template() {
    return html`
      ${this.messages.map(message => html`
        <chat-message

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@artfulrobot
Comment options

Answer selected by artfulrobot
Comment options

You must be logged in to vote
3 replies
@artfulrobot
Comment options

@artfulrobot
Comment options

@kennyfrc
Comment options

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