0

Пытаюсь импортировать компонент и получаю ошибку:

"element type is invalid expected a string (for built-in components) or a class/function".

Основной файл index.android.js:

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';

import {Text2} from './components/Text2';

class p001_lesson extends Component {
render() {
return (
<View>
<Text2/>
</View>
);
}
}

AppRegistry.registerComponent('p001_lesson', () => p001_lesson);

Второй файл Text2.js:

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


class Text2 extends Component {
    render() {
        return some text here
    }
}

Как исправить импорт?

0

1 ответ 1

0

Для использования компонента Text2 в другом файле его необходимо экспортировать:

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


class Text2 extends Component {
  render() {
    return <Text>some text here</Text>
  }
}

export default Text2;

И в файле index.android.js подключить следующей строкой:

import Text2 from './components/Text2';

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.