【问题标题】:React Native Import反应原生导入
【发布时间】:2023-04-01 10:20:01
【问题描述】:

我们可以使用单个关键字而不是'' import { Text, TextInput, Button, StyleSheet, View } from 'react-native'; ” 在 react native 中?“Text、TextInput、Button、StyleSheet、View”是否有可用的 Single 关键字选项?

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】:

    您可以import ReactNative from 'react-native' 并将它们用作&lt;ReactNative.View/&gt; 等等,但我不建议这样做。这不是 99% 的 RN 开发人员所期望的阅读方式。

    【讨论】:

    • 回答很有帮助。
    • 从'react-native'导入{按钮,样式表,视图};解构是 Reactjs 和 React Native 中的标准常见做法,你应该坚持下去。但是是的,您可以使用点表示法,但不建议使用。
    猜你喜欢
    • 2021-10-05
    • 2021-03-27
    • 2021-11-06
    • 2021-02-18
    • 1970-01-01
    • 2020-06-05
    • 2018-06-23
    • 2018-04-17
    相关资源
    最近更新 更多