Merge the contents of 2 DOM elements
npm install element-merge[![NPM Version][npm-img]][npm-url]
[![Build Status][cli-img]][cli-url]
[![Support Chat][git-img]][git-url]
[element-merge] is a 1.52 kB zero-dependency module that patches an
element with the contents of another element.
All diffing functionality is derived from [domdiff], while this package
specifically manages patching.
``html`
`html`
Add [element-merge] to your project:
`bash`
npm install element-merge
Import [element-merge]:
`js
import elementMerge from 'element-merge';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
const fragment = document.createRange().createContextualFragment(
You clicked ${count} times
); fragment.querySelector('button').onclick = () => setCount(count + 1);
elementMerge(document.body, fragment);
}
connect(Example)();
``[cli-img]: https://img.shields.io/travis/jonathantneal/element-merge.svg
[cli-url]: https://travis-ci.org/jonathantneal/element-merge
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
[git-url]: https://gitter.im/postcss/postcss
[npm-img]: https://img.shields.io/npm/v/element-merge.svg
[npm-url]: https://www.npmjs.com/package/element-merge
[domdiff]: https://github.com/WebReflection/domdiff
[element-merge]: https://github.com/jonathantneal/element-merge