【问题标题】:What do the angle brackets and asterisk mean in React?React 中的尖括号和星号是什么意思?
【发布时间】:2018-07-15 20:57:15
【问题描述】:

这个表达式中的尖括号和星号是什么意思?

class MainScreen extends React.Component<*> {
  render() {

【问题讨论】:

    标签: javascript reactjs react-native


    【解决方案1】:

    这是一个Flow 类型的参数。它指定 Flow 应该推断第一个类型参数的类型,换句话说,推断道具的形状,请参阅this answer on &lt;*&gt;。这实质上是让您为 Flow 指定任何形状的对象以推断其类型。假设你有两个道具,foobar。你可以这样做:

    type Props = {
      foo: number,
      bar: string
    };
    
    class MyComponent extends React.Component<Props> { … }
    

    或者,如果你不想要proptyping,你可以这样做:

    class MyComponent extends React.Component<*> { … }
    

    并且访问道具都是一样的。 Flow 只是推断它是一个带有foobar 的对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-26
      • 2011-09-30
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2022-06-19
      相关资源
      最近更新 更多