UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

37 lines (36 loc) 1.05 kB
"use client"; import "core-js/modules/web.dom-collections.iterator.js"; import React, { useCallback, useContext, useEffect, useRef } from 'react'; import SnapshotContext from './SnapshotContext'; import DataContext from '../../DataContext/Context'; function SnapshotProvider(props) { const { name, children } = props; const { snapshotsRef } = useContext(DataContext) || {}; const mountedFieldsRef = useRef(); 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 React.createElement(SnapshotContext.Provider, { value: contextValue }, children); } SnapshotProvider._supportsSpacingProps = undefined; export default SnapshotProvider; //# sourceMappingURL=Snapshot.js.map