overleaf/services/web/frontend/js/shared/context/split-test-context.js
Alexandre Bourdin 7e6839b0af Merge pull request #4715 from overleaf/ab-project-members-modal-split-test
Share modal split test

GitOrigin-RevId: 274450564e1cbfc3ba3ec7c2ca60dfeda552a536
2021-08-20 08:04:05 +00:00

43 lines
880 B
JavaScript

import { createContext, useContext, useMemo } from 'react'
import PropTypes from 'prop-types'
import getMeta from '../../utils/meta'
export const SplitTestContext = createContext()
SplitTestContext.Provider.propTypes = {
value: PropTypes.shape({
splitTestVariants: PropTypes.object.isRequired,
}),
}
export function SplitTestProvider({ children }) {
const value = useMemo(
() => ({
splitTestVariants: getMeta('ol-splitTestVariants') || {},
}),
[]
)
return (
<SplitTestContext.Provider value={value}>
{children}
</SplitTestContext.Provider>
)
}
SplitTestProvider.propTypes = {
children: PropTypes.any,
}
export function useSplitTestContext(propTypes) {
const context = useContext(SplitTestContext)
PropTypes.checkPropTypes(
propTypes,
context,
'data',
'SplitTestContext.Provider'
)
return context
}