How to import component in react native past two folders?

Whenever I try to import a component that is two or more folders back I get an issue. Using ../Folder works fine, but if I try to use …/Folder I get a module error. How do I get through the directory?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use ../.. to go up two directories.

Method 2

If you are trying to import for example index.css,
case 1: Same folder
import ‘./index.css’;

case 2: one dir up
import ‘../index.css’;

case 3: two dir up
import ‘../..index.css’;

Method 3

Simply go back by one level using “../”
Now for 2 levels and so on append “../”

This is for 2 level back.

../../YOUR_PATH/FILE_NAME

example:

/src/component/form/file1.js

If above file need to reach another file in dir parallel to ‘component’ as in above path i.e. ‘/src/assets/file.css’ so path in file1.js would be as following:

../../assets/file.css


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x