React Native Import

问题描述 投票:1回答:1

我们可以使用单个关键字代替''从'react-native'导入{Text,TextInput,Button,StyleSheet,View}; “在react native中?”是否有任何可用选项“ Text,TextInput,Button,StyleSheet,View”的单个关键字?

import { Button, StyleSheet, View } from 'react-native';

export default class ButtonBasics extends Component {
  _onPressButton() {
    alert('You tapped the button!')
  }

  render() {
    return (
      <View style={styles.container}>

        <View style={styles.buttonContainer}>
          <Button
            onPress={this._onPressButton}
            title="Press Me"
            color="#841584"
          />
        </View>
        <View style={styles.alternativeLayoutButtonContainer}>
          <Button
            onPress={this._onPressButton}
            title="This looks great!"
          />

        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
   flex: 1,
   justifyContent: 'center',
  },
  buttonContainer: {
    margin: 20
  },
  alternativeLayoutButtonContainer: {
    margin: 20,
    flexDirection: 'row',
    justifyContent: 'space-between'
  }
});
react-native react-component
1个回答
5
投票

您可以import ReactNative from 'react-native'并将其用作<ReactNative.View/>,依此类推,但我不建议这样做。这不是99%的RN开发人员期望阅读的方式。

© www.soinside.com 2019 - 2024. All rights reserved.