Macnux
Macnux

Reputation: 451

importing Text gives error

Im trying to work with text and im following a tutorial that says in order to work with text just type this

var React = require('react');
var Text = React.Text;

and then you can use it and it works with him

but with me it did not work and gives error says

element type is invalid expected a string 

and in order to make it work i wrote

import {Text} from 'react-native';

so why is this difference?

i think that the first one familiar to me than the second one

Upvotes: 0

Views: 39

Answers (1)

martinarroyo
martinarroyo

Reputation: 9701

You are searching in two different places. In the first attempt you are looking inside the react package, which is the same one you would use for React on the web. Of course, it does not make much sense having a React Native-specific component in that package, and that is the reason why you are not finding it. In the second one, you are querying a completely different package, the react-native one, which does have the element you are looking for.

Upvotes: 2

Related Questions