简体   繁体   English

... react-native function 组件中的属性

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

I have the following function component in a react-native app.我在 react-native 应用程序中有以下 function 组件。 In second line of code, there is ...attributes which is confusing.在第二行代码中,有一个令人困惑的...attributes While I understand that it represents spread syntax in newer JavaScript version, but I cannot find what does attributes mean.虽然我知道它代表较新的 JavaScript 版本中的传播语法,但我找不到attributes的含义。 If it said ..props then that is understandable.如果它说..props那是可以理解的。 I tried to google but couldn't find any suitable answer.我试图谷歌但找不到任何合适的答案。

Question

What does attrributes denote in second line of code snippet below?下面代码片段的第二行中的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 is the name of the newly created constant containing the rest properties from props . attributes是新创建的常量的名称,其中包含props中的 rest 属性。

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

So if you use your component like this <Loader loading foo="bar" /> then attributes will be equal to { foo: 'bar' }因此,如果您像这样使用组件<Loader loading foo="bar" />那么attributes将等于{ foo: 'bar' }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM