故事书StoryRouter故事已标记为必填

时间:2019-09-29 17:37:24

标签: javascript reactjs storybook

我正在将React与Storybook一起使用。我的组件之一使用Link,并对需要将任何Link组件包装在路由器中做出反应,这就是为什么我使用npm模块StoryRouter。一切正常,但我在控制台上收到一个警报。

// simple ListItem.tsx
import React from 'react';
import { Link } from 'react-router-dom';
export const ListItem = () => {
    return (
        <Link to={{pathname:`/page/1`}}>
            go to page
        </Link>
    );
}

// ListItem.stories.tsx
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import StoryRouter from 'storybook-react-router';
import { ListItem } from "./ListItem";
let props = {
    text:"Introduction to limits",
}
storiesOf("ListItem", module)
    .addDecorator(StoryRouter()) // this causes the alert
    .add("default", () => <ListItem {...props} />)

当我在getStorybook上查看组件时,控制台上会显示一条消息

    Warning: Failed prop type: The prop `story` is marked as required in `StoryRouter`, but its value is `undefined`.
        in StoryRouter (created by storyFn)
        in storyFn
        in ErrorBoundar

1 个答案:

答案 0 :(得分:0)

将故事书反应路由器升级到1.0.8。该错误已修复。参见:https://github.com/gvaldambrini/storybook-router/issues/43