question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

props attribute is null when declaring child component inside parent component

See original GitHub issue

Hi @ducksoupdev, Please look at this code

import { html, renderer } from 'https://cdn.skypack.dev/@ficusjs/renderers@4/htm'
import { createCustomElement, createComponent } from 'https://cdn.skypack.dev/ficusjs'

createCustomElement('hello-world', {
  renderer,
  state() {
    return {me: {name: 'ficusjs', type: 'javascript'}}
  },
  handleClick (e) {
    window.alert('Hello to you!')
  },
  childComponent: createComponent('comp-child', {
    props: {parent: {type: Object, required: true, observed: false}, foo: {type: Object, required: true, observed: false}},
    render () {
      return html`<p>Hello ${this.props.foo.name}</p>`
    }
  }),
  render () {
    return html`
      <div>
        <comp-child parent=${this} foo=${this.state.me}></comp-child>
        <button type="button" onclick="${this.handleClick}">Click me</button>
      </div>
    `
  }
})

this.state.me has value but cannot be transfered to child’s props. By the way, what is the better way to communicate between parent and child (child is declared inside of parent)? Without using event-bus to subcribe. I use parent=${this} as property but haven’t test it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21

github_iconTop GitHub Comments

1reaction
ducksoupdevcommented, Feb 13, 2022

I have created a codepen that matches your description.

https://codepen.io/ducksoupdev/pen/VwrzjJd

Components are registered with the CustomElementRegistry so must be statically declared. This can be done using a creator function as shown in the codepen.

0reactions
Dan-Docommented, Feb 17, 2022

That’s great. Thank you very much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing prop from child to parent is null - Stack Overflow
You need to bind your function in constructor. (in parent component) constructor(props) { super(props) this.yourFunction = this.
Read more >
How to Pass Props Object from Child Component to Parent ...
This is where React props would come into the picture. We pass data by adding some HTML attributes and we assign the data...
Read more >
Template Refs - Vue.js
ref is a special attribute, similar to the key attribute discussed in the v-for chapter. It allows us to obtain a direct reference...
Read more >
Docs • Svelte
Svelte uses the export keyword to mark a variable declaration as a property or prop, which means it becomes accessible to consumers of...
Read more >
How to use Props in React - Robin Wieruch
Everything you need to know about props in React. How to pass props to components, how to set default props, how to know...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found