Combo
  • Combo.js
  • Guide
    • Concepts
      • Lifecycle Methods
  • APIs
    • Component
      • canMount
      • canUnmount
      • canUpdate
      • created
      • el
      • isMounted
      • mount
      • mounting
      • mounted
      • on
      • props
      • receiving
      • received
      • refresh
      • render
      • rendered
      • state
      • unmount
      • unmounting
      • unmounted
      • update
      • updated
      • updating
  • FAQs
    • Props
    • State
    • Events
    • Ajax
Powered by GitBook
On this page
  • Where do I define default component props?
  • How do I pass props to a mounted component?
  • How do I pass props to an unmounted component?
  1. FAQs

Props

Where do I define default component props?

Inside the created() life cycle hook.

import { Component } from "combo-js";

const Example = new class extends Component {
    created() {
        this.props = {
            name: "world"
        }
    }
    render() {
        return `
            <div>Hello ${this.props.name}</div>
        `;
    }
}();

Example.mount(document.getElementById("root"));
<div id="root"></div>

How do I pass props to a mounted component?

Pass them through the mount() method.

import { Component } from "combo-js";

const Example = new class extends Component {
    created() {
        this.props = {
            name: ""
        }
    }
    render() {
        return `
            <div>Hello ${this.props.name}</div>
        `;
    }
}();

Example.mount(document.getElementById("root"), {
    name: "Combo"
});
<div id="root"></div>

How do I pass props to an unmounted component?

Pass them through the constructor function.

import { Component } from "combo-js";

const Foo = new class extends Component {
    created() {
        this.props = {
            name: ""
        }
    }
    render() {
        return `
            ${Bar.render(this.props)}
        `;
    }
}();

const Bar = (props) => {
    return {
        <div>Hello ${props.name}</div>
    }
};

Example.mount(document.getElementById("root"), {
    name: "Combo"
});

Can I manipulate props?

You can manipulate props in the receiving() life cycle method.

<div id="root"></div>
PreviousFAQsNextState

Last updated 6 years ago