Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Atom/Nuclide provide auto-import for react-native components

Is there a way to have Atom generate import statements for components I add to my react-native files?

When adding a standard react-native component (like a Navigator) while editing react-native code in the Atom/Nuclide editor, I find I need to manually write import statements. Is this expected?

In the traditional native IDE world (Android Studio, XCode), import statements are auto-generated by the IDE. Is there an atom package for this?

Example:

import React, { Component } from 'react'
import { AppRegistry } from 'react-native'

class TestProject extends Component {
  render() {
    return (
      <Navigator
      ...

In the above, line 2 should become:

import { AppRegistry, Navigator } from 'react-native'
like image 975
Daniel Smith Avatar asked Aug 18 '16 00:08

Daniel Smith


People also ask

How do I run react native app in atom?

Open Atom preferences and go to Install tab. Here you can search and install each of the packages mentioned below and get ready to code your mobile applications in React Native. I have tried to keep the plugins to minimum, so as not to clutter Atom.

Do I need to import react in react native?

You no longer need to import React from "react" . Starting from the release 17 of React, JSX is automatically transformed without using React. createElement . However, other exports like hooks must be imported.

What is import in react native?

In React we use the keyword import and from to import a particular module or a named parameter. Let's see the different ways we can use the import operation in React Native Application. Importing default export: Each module in reacts native needs at least one default export.

Which syntax is used to import just the component from the react library?

Importing Components from React Bootstrap It is the basic syntax that's used to import the specific components from the library, but you can still import it using other ways that you will learn in the next section of this guide.


1 Answers

For React-Native app development, Atom works as an editor only. The feature you are asking about isn't provided with Atom yet. Let's hope we will get an update in future which will include this feature.

But till then, give a shot to Visual Studio Code, where you'll need to install a an extension of React-Native Tools.

VSCode with React-Native Tools extension provides this functionality, where the import statements are generated automatically. We also get suggestions of available classes and methods at the time of development, which is really useful from developer's perspective. We can also debug and run the project directly from VSCode without console or native IDE like Android Studio or Xcode.

like image 95
Keyur Tailor Avatar answered Oct 17 '22 23:10

Keyur Tailor