UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

41 lines (40 loc) 1.16 kB
"use client"; import React, { useCallback, useContext, useEffect, useRef } from 'react'; import SnapshotContext from "./SnapshotContext.js"; import DataContext from "../../DataContext/Context.js"; import withComponentMarkers from "../../../../shared/helpers/withComponentMarkers.js"; import { jsx as _jsx } from "react/jsx-runtime"; function SnapshotProvider(props) { const { name, children } = props; const { snapshotsRef } = useContext(DataContext) || {}; const mountedFieldsRef = useRef(undefined); if (!mountedFieldsRef.current) { mountedFieldsRef.current = new Map(); } const setMountedField = useCallback((path, state) => { mountedFieldsRef.current.set(path, state); }, []); useEffect(() => { if (snapshotsRef) { snapshotsRef.current.set(name, mountedFieldsRef.current); } }, [snapshotsRef, name]); const contextValue = { name, setMountedField }; return _jsx(SnapshotContext, { value: contextValue, children: children }); } withComponentMarkers(SnapshotProvider, { _supportsSpacingProps: undefined }); export default SnapshotProvider; //# sourceMappingURL=Snapshot.js.map