Answer the question
In order to leave comments, you need to log in
Is it legal to place an import at the bottom of a React component?
In React, by default, in almost all the source code that I have seen, the import is placed on top of the file in which the component is located. In the case of many imports (it's a code smell, by the way, I know it), when we open any component we need to scroll down, often a lot.
I believe the first thing we want to see when opening a component is the render method.
Is it a bad idea to put the import at the bottom of the file? It seems to work, but does it have any negative effects?
Answer the question
In order to leave comments, you need to log in
The idea is so-so.
firstly, no one does this, and you will create problems for anyone who will work with your code.
Secondly, imports work where they are written, if they are at the beginning, then everything will be fine in the file for sure. If they are at the end, then the result may be different.
If your only problem is that imports visually interfere and you are too lazy to scroll, then use folding:
When using normal navigation through the code, you will rarely get to the beginning of files at all.
You can count anything, other people may have a different opinion. If you work alone, you can do whatever you want, in a team such things should at least be discussed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question