【发布时间】:2017-06-29 14:47:37
【问题描述】:
我有点困惑哪些流类型与反应组件一起使用
这是我的代码的一部分:
// @flow
import React from 'react';
import Stage from '../../../shared/sections/Stage';
interface WithContent {
content: any,
}
class DynamicContent extends React.PureComponent {
props: {
content: [],
};
static componentsMap = {
dn_module_stage: Stage,
};
static getComponent(identifier: string): ?React$Element<WithContent> {
if (Object.prototype.hasOwnProperty.call(DynamicContent.componentsMap, identifier)) {
return DynamicContent.componentsMap[identifier];
}
return null;
}
static renderComponent(component: GenericComponent, key: number): ?React$Element<WithContent> {
const Component: any = DynamicContent.getComponent(component.type);
if (Component) {
return <Component key={key} content={component.content} />;
}
return null;
}
...
...
可能界面是不必要的,我应该只使用 ?React$Element,对吗?
我正在尝试输入这一行但没有成功,我应该使用什么来代替任何?
const Component: any = DynamicContent.getComponent(component.type);
是否有正确使用 flow 和 react 的良好资源?我刚刚找到一篇文章和官方文档,这并不多。任何带有代码示例的 github 存储库?
【问题讨论】:
标签: javascript reactjs typescript flowtype flow-typed