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

Error: Cannot read 'writeToFile' of undefined #6

Open
kamleshchandnani opened this issue Feb 11, 2017 · 8 comments
Open

Error: Cannot read 'writeToFile' of undefined #6

kamleshchandnani opened this issue Feb 11, 2017 · 8 comments

Comments

@kamleshchandnani
Copy link

Package is also imported
import FileSystem from 'react-native-filesystem'

console.log('inside file writing', FileSystem)//getting FileSystem here
 let data = yield FileSystem.writeToFile('./productsData', JSON.stringify(productsData.Data))//cannot read writeToFile of undefined

Rebuilt after installng react-native-filesystem. Still no luck! Can somebody help

@paandahl
Copy link
Owner

Try this:

let data = await FileSystem.writeToFile('./productsData', JSON.stringify(productsData.Data))

@kamleshchandnani
Copy link
Author

@benwixen
I can't
Since I am using this inside my saga generators.
So await can't be used inside generator.

@paandahl
Copy link
Owner

Hi, I'm not very familiar with sagas or yields, and not entirely sure if the yield-keyword is the issue. Can you use promises?

let promise = FileSystem.writeToFile('./productsData', JSON.stringify(productsData.Data));
promise.then(data => {
  // do your thing with 'data' here
});

@kamleshchandnani
Copy link
Author

@benwixen BTW where this data is stored physically? I am having data ~15mb

@paandahl
Copy link
Owner

It's stored on the persistent disk of the device. The exact location depends on operating system, and storage class (the default class is storage.backedUp):

https://github.com/benwixen/react-native-filesystem/blob/master/docs/reference.md#filesystemstorage

@paandahl
Copy link
Owner

Btw, if you're downloading this data, it will be more efficient to use a file download-library. If you first pass the data through the javascript side, it will have to stay in memory until it's written, and then be passed over the React Native bridge (not very performant).

@kamleshchandnani
Copy link
Author

yield is not the issue. because yields gives you the flexibilities of await. So the issue is something else.
RNFileSystem is not getting initialized from react-native.
RNFileSystem is undefined and hence the error RNFileSystem.writeToFile (cannot read writeToFile of undefined)

@paandahl
Copy link
Owner

I'm sorry, but it's hard for me to say exactly what your problem might be.

If you can make a minimal project that reproduces the issue, and share it through Github or other means, I will try to pinpoint / fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants