overleaf/services/web/frontend/stories/hooks/use-scope.tsx
Alf Eaton d91ee50762 Standardise scope/context usage in Storybook stories (#7842)
GitOrigin-RevId: 109a4357fc3b083ffbd3af5b8c98acf0f655f297
2022-05-17 08:04:12 +00:00

16 lines
408 B
TypeScript

import { merge } from 'lodash'
import { useLayoutEffect, useRef } from 'react'
/**
* Merge properties with the scope object, for use in Storybook stories
*/
export const useScope = (scope: Record<string, unknown>) => {
const scopeRef = useRef(null)
if (scopeRef.current === null) {
scopeRef.current = scope
}
useLayoutEffect(() => {
merge(window._ide.$scope, scopeRef.current)
}, [])
}