0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/.storybook/kea-story.tsx
Marius Andra 9d7b53ea1b
chore(frontend): remove <Provider> (#10556)
* chore(frontend): remove <Provider>

* this is also not how we use storybook
2022-06-29 16:08:30 +02:00

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
}