我有一个Tooltip组件,该组件使用createPortal
将自己放置在root_tooltips
DOM元素中。它在整个应用程序中都能正常运行,但在Storybook上无法正常运行。
但是,当尝试为Storybook
编写故事时,我无法解决错误。我将其范围缩小到了门户,但这并不一致。
对于这样的故事:
storiesOf('Tooltip', module).add('Tooltip renders', () => {
return (<div>
{
createPortal(
<p>YO</p>,
document.getElementById('root__tooltips') || document.body
)
}
</div>)
})
故事书中断并返回:
TypeError: Cannot read property 'children' of undefined
at getData (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:3740:33)
at Node (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:3761:18)
at renderWithHooks (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:187767:18)
at mountIndeterminateComponent (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:190001:13)
at beginWork$1 (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:191145:16)
at HTMLUnknownElement.callCallback (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:173006:14)
at Object.invokeGuardedCallbackDev (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:173056:16)
at invokeGuardedCallback (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:173113:31)
at beginWork$$1 (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:195876:7)
at performUnitOfWork (http://localhost:6006/vendors~main.d101792a2f274379b7cf.bundle.js:194870:12)