my-sample-component
v0.0.1
Published
my-sample-component is a vanilla javascript component which will work in any frontend framework. You can install from npm like this:
Downloads
3
Readme
my-sample-component
my-sample-component is a vanilla javascript component which will work in any frontend framework. You can install from npm like this:
npm install --save my-sample-component
Usage: Javascript (assumes es module)
import Component from 'my-sample-component'
let component = new Component({target:document.body, props: { name: 'Init Value' });
component.name = 'Updated Value';
The "target" is where the component is created. Here it is added to the html body with "document.body", but it could also be document.getElementById('id-of-html-element').
You initialize properties with "props" and you can change the prop values by just assigning the props to new values - this will be updated in the UI.
Usage: Legacy Javascript
Below you can see how to use the component with vanilla js.
...
<head>
...
<script src="https://unpkg.com/[email protected]/index.js"></script>
</head>
<body>
<script>
let component = new Component({target:document.body})
</script>
</body>
Usage: Web Component (aka. Custom Element)
You can use it as a web component.
<head>
<script src="https://unpkg.com/[email protected]/index.js"></script>
</head>
<body>
<my-component name="Init Value" />
</body>
Svelte Component
<script>
import Component from 'my-sample-component';
</script>
<Component/>
Pelte
This component was created by pelte (aka publish-svelte)