mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-27 07:21:44 +00:00
e9e36737e6
[web] SplitTestBadge based on split test phase and badge config GitOrigin-RevId: e178ca864fd6619ff61a2a84fc1ccb5d54e0a814
45 lines
984 B
JavaScript
45 lines
984 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,
|
|
splitTestInfo: PropTypes.object.isRequired,
|
|
}),
|
|
}
|
|
|
|
export function SplitTestProvider({ children }) {
|
|
const value = useMemo(
|
|
() => ({
|
|
splitTestVariants: getMeta('ol-splitTestVariants') || {},
|
|
splitTestInfo: getMeta('ol-splitTestInfo') || {},
|
|
}),
|
|
[]
|
|
)
|
|
|
|
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
|
|
}
|