Skip to content

Integrations

Frameworks

DNA composition is tested across different frameworks.

FrameworkVersionUpdate a propertySlot textSlot elementsNamed slotsBuiltin elements
Angular20⚠️¹
Lit3
Preact10⁴
React19⚠️²
Svelte5✅³
uhtml4
Vue3
  • ¹ does not create and handle builtin custom elements. [issue]
  • ² does not correctly update properties for builtin custom elements. [issue]
  • ³ full support since v5.38.5
  • ⁴ full typings support from v11

JSX

DNA has export specifiers for JSX integration with different frameworks.

ts
import '@chialab/dna/react';
ts
import '@chialab/dna/preact';
ts
import '@chialab/dna/svelte';

declare global {
	namespace App {
        // ...
    }
}

Hydration

Many frameworks support hydration of server-rendered HTML. DNA elements rendering starts once the node is connected, so it may interfere with the hydration process. To avoid this, you can delay DNA rendering until the framework is ready. For example, in Svelte

ts
import { isHydrating } from '@chialab/dna';

export const init = () => {
	isHydrating(true);
};
svelte
<script lang="ts">
	import { onMount } from 'svelte';
	import { isHydrating } from '@chialab/dna';

	onMount(() => {
		isHydrating(false);
	});
</script>

View libraries

Sometimes you need to encapsulate in DNA another UI library, like Mapbox or Pickr. Since DNA components are DOM nodes, the integration is possible using the element context as library param:

ts
import { Component, customElement } from '@chialab/dna';
import Pickr from '@simonwep/pickr';

@customElement('color-picker')
class ColorPicker extends Component {
    private pickr: Pickr;

    connectedCallback() {
        super.connectedCallback();
        this.pickr = new Pickr({
            el: this,
        });
    }

    disconnectedCallback() {
        this.pickr.destroyAndRemove();
        super.disconnectedCallback();
    }
}

Released under the MIT License.