overleaf/services/web/frontend/stories/hooks/use-scope.tsx

17 lines
408 B
TypeScript
Raw Normal View History

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)
}, [])
}