overleaf/services/web/frontend/stories/hooks/use-scope.tsx
Timothée Alby 5bc28ffa8c Merge pull request #8211 from overleaf/ii-settings-ts-storybook-fixes
[web] Fix TS issues in stories

GitOrigin-RevId: 093102351c2ca3d4bf05e6de2ce0dda55d421df1
2022-05-31 08:04:22 +00:00

16 lines
429 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<typeof scope | null>(null)
if (scopeRef.current === null) {
scopeRef.current = scope
}
useLayoutEffect(() => {
merge(window._ide.$scope, scopeRef.current)
}, [])
}