Home > Mobile >  In what order should imports be done in React?
In what order should imports be done in React?

Time:05-21

I know I have to import React first in component files:

import React from 'react';
// other imports...

I've also heard that imports with styles and images should be imported last:

// other imports...
import * as Styles from './styles.css';
import exampleIcon from '../icons/example-icon.svg';

Why should I import icons, images and styles last? What about the order of other imports (components, utilities, constants, etc.) - is there a standard/documentation for imports order?

CodePudding user response:

I think We don't have any standard for that, my standard is like this, and I have seen a lot of people import code in this order.

React and React Hooks

packages

components

styles

CodePudding user response:

I don't have any standard doc for that, but there's easy way which makes you not to care about that anymore.. If you use Visual Code for developing, just install vsc-organize-imports extension for Visual Code.. It will help you to organize imports automatically by default options.. Good luck..

  • Related