dom-mapper

Small utility to map data attributes to JS objects

Usage no npm install needed!

<script type="module">
  import domMapper from 'https://cdn.skypack.dev/dom-mapper';
</script>

README

Small utility to map data attributes to JS objects

Example:

Given the following HTML:

<div id="upload" data-item-count=4></div>

import * as DOM from 'dom-mapper';

// `UploadView` is a react view

// Any CSS supported by querySelectorAll is supported
var map: DOM.ElementMap = {
    '#upload': UploadView,
};

DOM.iterateElementMap(map, (id: string, Klass: any, el: Element, props: any) => {
    // props will be `{itemCount:4}` for #upload
    ReactDom.render(<Klass {...props} />, el);
})

License

MIT