I'm wondering the best way for me to use a full path for my project.
For example, if I am importing a component, I don't want to do import Component from '../components/Component'
, rather just do import Component from 'app/components/Component';
Can someone help me out?
The most convenient way : Use react-native-document-picker, on selection it will give you a Relative path, something like this content://com.android...... . Pass that Relative path to Stat(filepath) function of the react-native-fetch-blob library. The object will return absolute path.
Right-click the src folder and select Mark Directory as and Click Resource Root . Next select Preferences -> Editor -> Code Style -> JavaScript -> Imports and Check Use paths relative to the project, resource or source roots and then Click Apply .
To have an absolute path,
I am considering your package.json is in the root.
Inside, your package.json add a new property name with value whatever you want i.e
"name": "root"
and then import all your routes relative to that route
import Component from root/components/Component
You can use absolute path by figuring out the name of your app in the package.json name section and then using it in front of your absolute path i.e
import Component from MyApp/components/Component
Here's more information on describing the issue https://github.com/facebook/react-native/issues/3099
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With