Skip to content

Instantly share code, notes, and snippets.

@martsie
Created June 10, 2020 06:02
Show Gist options
  • Save martsie/7a284721fc278724886bb6685919d36c to your computer and use it in GitHub Desktop.
Save martsie/7a284721fc278724886bb6685919d36c to your computer and use it in GitHub Desktop.
Lewagon #404 Component template
import MyComponent from "./components/MyComponent";
const initPlugin = (querySelector, Component) => {
const els = document.querySelectorAll(querySelector);
if (els) {
els.forEach(el => {
Component(el);
});
}
};
initPlugin(".js-my-component", MyComponent);
const MyComponent = (rootElement) => {
const subEl = rootElement.querySelector('.js-some-btn');
console.log(rootElement, "i'm working!");
};
export default MyComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment