簡體   English   中英

React中的尖括號和星號是什么意思?

[英]What do the angle brackets and asterisk mean in React?

尖括號和星號在這個表達式中的含義是什么?

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

這是一個Flow類型的參數。 它指定Flow應該推斷出第一個類型參數的類型,換句話說推斷出道具的形狀,請參閱<*>上的這個答案 這基本上是讓你為Flow指定一個任何形狀的對象來推斷它的類型。 假設你有兩個道具, foobar 你可以這樣做:

type Props = {
  foo: number,
  bar: string
};

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

或者,如果你不想要支持,你可以這樣做:

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

並且訪問道具都是一樣的。 Flow只是推斷它是foobar的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM