React Native “imports”

I am trying to develop a react-native book-searching app and have found this online as a helper tool: https://www.appcoda.com/react-native-introduction/

However, the site is from 2015, so some of the syntax is not properly updated.

I've run into the following issue:

The code that they tell me to use is as follows:

'use strict';

var React = require('react-native');

var Books = require('./Books');
var Search = require('./Search');

var {
    AppRegistry,
    TabBarIOS,
    Component
   } = React;

When I used that, I arrived at an Error Message telling me to use import React, { Component } from 'react'; instead of import React from 'react-native';

In my attempt to update it to the latest version of React, I arrived at:

'use strict';

import React, { Component } from 'react';

var Books = require('./Books');
var Search = require('./Search');

var {
    AppRegistry,
    TabBarIOS
   } = React;

This is still causing multiple errors. Can someone explain how to properly do what I am trying to do?

You're trying to import AppRegistry and TabBarIOS from React instead of react-native and some syntax errors. Change:

var {
    AppRegistry,
    TabBarIOS
   } = React;

to

import {
    AppRegistry,
    TabBarIOS
   } from 'react-native';

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue