mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-29 02:46:32 +01:00
5c783c744c
* chore: Add debug info to JSX output * Pin React to `^16.14.0` instead of `^16.13.0` * Remove redundant `React`s * Add `@babel/preset-react` for Storybook * Update babel.config.js
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { createMemoryHistory } from 'history'
|
|
import { initKea } from '~/initKea'
|
|
import { router } from 'kea-router'
|
|
import { getContext } from 'kea'
|
|
import { useEffect, useState } from 'react'
|
|
import { App } from 'scenes/App'
|
|
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
|
|
import { worker } from '~/mocks/browser'
|
|
import { teamLogic } from 'scenes/teamLogic'
|
|
import { userLogic } from 'scenes/userLogic'
|
|
|
|
export function resetKeaStory(): void {
|
|
worker.resetHandlers()
|
|
|
|
const history = createMemoryHistory({})
|
|
;(history as any).pushState = history.push
|
|
;(history as any).replaceState = history.replace
|
|
initKea({ routerLocation: history.location, routerHistory: history })
|
|
featureFlagLogic.mount()
|
|
teamLogic.mount()
|
|
userLogic.mount()
|
|
router.mount()
|
|
const { store } = getContext()
|
|
store.dispatch({ type: 'storybook init' })
|
|
}
|
|
|
|
export function KeaStory<T = React.ReactNode>({ children }: { children: T }): T | JSX.Element | null {
|
|
const [didReset, setDidReset] = useState(false)
|
|
useEffect(() => {
|
|
if (!didReset) {
|
|
resetKeaStory()
|
|
setDidReset(true)
|
|
}
|
|
}, [didReset])
|
|
|
|
return didReset ? children || <App /> : null
|
|
}
|