UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

36 lines (35 loc) 991 B
"use client"; 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