Closed karolskolasinski closed 3 years ago
@karolskolasinski HTM doesn't use Web Components, object values are supported. To pass an object, use ${}
:
let someObject = { foo: 'bar' };
// pass an object by reference:
html`<${Foo} value=${someObject} />`;
// pass an object literal:
html`<${Foo} value=${{ foo: 'bar' }} />`;
// spread an object to pass its properties as props:
html`<${Foo} ...${someObject} />`; // by reference
html`<${Foo} ...${{ foo: 'bar' }} />`; // object literal
In your example, the code you suggested should work as you described:
class App extends Component {
// <snip>
render({ page }, { todos = [] }) {
// `page` is whatever you passed - in this case, it's `object`.
return html`
<div class="app">
<${Header} name="ToDo's (${page.name})" />
...
</div>
`;
}
}
let object = { name: 'Page Name' };
render(html`<${App} page=${object} />`, document.body);
Closing since this seems like a question with an answer, but please re-open if I've missed something!
How can i pass an object as an attribute:
render(html`<${App} page=${object} />`, document.body);
Everything that you pass byhtml
as an attribute in web components is a string, but maybe I doing something wrong.