@xoid/svelte
Version:
Framework-agnostic state management library designed for simplicity and scalability
18 lines (15 loc) • 553 B
JavaScript
import { atom } from 'xoid';
import { onDestroy } from 'svelte';
import { useAdapter } from './useAdapter';
export { useAtom } from './useAtom';
/* eslint-disable react-hooks/rules-of-hooks */
function useSetup(fn, props) {
if (arguments.length > 1) {
const $props = atom(() => props);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
onDestroy(props.subscribe((value) => $props.set(value)));
return useAdapter(() => fn($props));
}
return useAdapter(fn);
}
export { useSetup };