簡體   English   中英

... react-native function 組件中的屬性

[英]...attributes in react-native function component

我在 react-native 應用程序中有以下 function 組件。 在第二行代碼中,有一個令人困惑的...attributes 雖然我知道它代表較新的 JavaScript 版本中的傳播語法,但我找不到attributes的含義。 如果它說..props那是可以理解的。 我試圖谷歌但找不到任何合適的答案。

下面代碼片段的第二行中的attrributes表示什么?

  const Loader = (props) => {
  const { loading, loaderColor, loaderText, ...attributes } = props;

  return (
    <Modal
      transparent={true}
      animationType={'none'}
      visible={loading}
      onRequestClose={() => {
        console.log('close modal');
      }}>
      <View style={styles.modalBackground}>
        <View style={styles.activityIndicatorWrapper}>
          <ActivityIndicator
            animating={loading}
            color={loaderColor? loaderColor : '#0000ff'}
            size={Platform.OS === 'ios' ? 'large' : 75}
          />
          {loaderText ? (
            <View style={{ flexDirection: 'row' }}>
              <Text style={styles.modalText}>{loaderText}</Text>
            </View>
          ) : (
            ''
          )}
        </View>
      </View>
    </Modal>
  );
};

attributes是新創建的常量的名稱,其中包含props中的 rest 屬性。

 const { a, b, ...objectContainingEveryOtherPropertyExceptAB } = { a: 1, b: 2, c: 3, d: 4 }; console.log(objectContainingEveryOtherPropertyExceptAB);

因此,如果您像這樣使用組件<Loader loading foo="bar" />那么attributes將等於{ foo: 'bar' }

暫無
暫無

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

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