【问题标题】:Confused about Flow typing with React Components对 React 组件的流类型感到困惑
【发布时间】: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


    【解决方案1】:

    您可以在 Github 上查看代码中使用的流量存储库。比如https://github.com/facebook/flux/blob/master/examples/flux-async/src/views/AppView.js

    【讨论】:

      猜你喜欢
      • 2012-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多