Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React Native] Can't find variable: __dirname #137

Closed
hiromitz opened this issue Nov 20, 2019 · 6 comments · Fixed by #149
Closed

[React Native] Can't find variable: __dirname #137

hiromitz opened this issue Nov 20, 2019 · 6 comments · Fixed by #149
Labels
area: react-native help wanted Extra attention is needed

Comments

@hiromitz
Copy link

I simply added

import useSWR from 'swr'

then error occurred Can't find variable: __dirname
__dirname is on compiled dist code, but React Native doesn't support _dirname.

@90dy
Copy link

90dy commented Nov 21, 2019

The __dirname variable is located in node_modules/swr/dist/index.js
I need to import swr/esm to bypass it

@shuding shuding added help wanted Extra attention is needed area: react-native labels Nov 25, 2019
@n3tr
Copy link
Contributor

n3tr commented Nov 26, 2019

@quietshu I can help take a look on this one :)

@mohmdalfaha
Copy link

I am facing a similar issue but when importing it from import useSWR from '@zeit/swr' it works fine @n3tr Thanks for maintaining this. Do you have any React native example. Because I am facing a hard time getting the cached data when the device is offline.

I am expecting this library to serve the most recent cached api response and when online it revalidates and bring the recent response. Does is it work this way or I am missing something. Thanks again @n3tr .

@n3tr
Copy link
Contributor

n3tr commented Nov 27, 2019

@mohmdalfaha doesn't it return a cached data when device is offine? 🤔

I only use swr in my hobby project and haven't thought about the online/offline thing 😅 .

I will help take a look when I have time. My idea is just creating custom fetch hook, observing netinfo event ,and revalidate if needed.

@shuding
Copy link
Member

shuding commented Nov 27, 2019

The current cache structure needs some refactoring to support async cache mechanisms. And after that, we will be able to support custom cache APIs like AsyncStorage.

@ramisalem
Copy link

@quietshu I really liked the amazing hook you built, Although I am wondering if it supports offline mode, I have tried it with offline mode but it did not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: react-native help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants