props attribute is null when declaring child component inside parent component
See original GitHub issueHi @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:
- Created 2 years ago
- Comments:21
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
That’s great. Thank you very much.