mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 18:26:15 +01:00
9d7b53ea1b
* chore(frontend): remove <Provider> * this is also not how we use storybook
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 React, { 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
|
|
}
|