UNPKG

molstar

Version:

A comprehensive macromolecular library.

33 lines 977 B
/** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { useEffect, useState } from 'react'; // eslint-disable-next-line export function useBehavior(s) { var _a = useState(s === null || s === void 0 ? void 0 : s.value), value = _a[0], setValue = _a[1]; useEffect(function () { if (!s) { if (value !== void 0) setValue(void 0); return; } var fst = true; var sub = s.subscribe(function (v) { if (fst) { fst = false; if (v !== value) setValue(v); } else setValue(v); }); return function () { sub.unsubscribe(); }; // eslint-disable-next-line }, [s]); return value; } //# sourceMappingURL=use-behavior.js.map