【问题标题】:Invariant Violation - Unable to import custom component react native不变违规 - 无法导入自定义组件反应原生
【发布时间】:2021-07-07 02:39:18
【问题描述】:

在阅读了许多其他类似的问题后,我仍然无法导入我的自定义组件。

这里是主视图:

import React from 'react';
import {Image, StyleSheet, Text, View} from 'react-native';
import {LOGO} from '../../assets/logo.png';
import {testingInput} from './testingInput';

function tempScreen({navigation}) {
    return (
        <View style={
            styles.container
        }>
            <View style={
                styles.topContainer
            }>
                <Image styles={
                        styles.logo
                    }
                    scoure={LOGO}
                    resizeMode={'cover'}/>
                <Text>
                    Here
                </Text>
            </View>


            <View style={
                styles.bottomContainer
            }>
                <testingInput/>
            </View>
        </View>
    )
}


const styles = StyleSheet.create({
    ...
})

export default tempScreen;

这里是 tempButton 文件:

import React, {Component} from 'react';
import {TextInput, StyleSheet} from 'react-native';

const testingInput = (prop) => {
    return (
        <TextInput style={
                styles.TextInput
            }
            placeholder="Email"
            color="#ffffff"
            placeholderTextColor="#ffffff"
            autoCapitalize="none"></TextInput>
    )
}

const styles = StyleSheet.create({
    TextInput: {

        height: 50,
        flex: 1,
        padding: 10,
        marginLeft: 20
    }
})


export default testingInput;

我收到了错误

“不变违规:组件testingInput 的视图配置getter 回调必须是一个函数(收到undefined)。确保以大写字母开头组件名称。”

任何帮助将不胜感激!

【问题讨论】:

  • 从'./testingInput'导入TestingInput;试试这个,让组件在前,后总是大写。

标签: javascript reactjs react-native


【解决方案1】:

当您使用默认导出时,您不需要解构导入。

使用export default testingInput;,您将导入import TestInput from './testinputfile。这里导入的名称并不重要

使用export testingInput;,您将导入import {functionName} from './testinputfile。这里导入的名字需要和导出的函数的名字一致

【讨论】:

  • 更改导入帮助,但我还需要将首字母大写来解决问题
猜你喜欢
  • 2018-12-19
  • 1970-01-01
  • 1970-01-01
  • 2020-07-02
  • 2020-03-13
  • 1970-01-01
  • 2021-10-05
  • 2021-11-06
  • 2019-06-21
相关资源
最近更新 更多