3

When I try to use npm install to use firebase with React native, I am getting errors.

Then when I try to use require for the firebase module, it says that the document can't be found.

Is there a way to utilize the firebase API with React native instead?

3

2 Answers 2

2

Firebase uses WebSockets, which currently is not supported by React Native. As of now, there is no good solution to integrate Firebase with React Native.

In lieu of requiring firebase as a module, you can indeed use the firebase API instead. If you were doing a simple get request, your fetch function would look like this:

var url = "https://YourDatabaseName.firebaseio.com/some/val.json";  
 fetch(url)
  .then((response) => response.json())
  .then((responseData) => {
    console.log(responseData);
  })
 .done();

For more information, you can check out a blog post I wrote about the topic here: http://anuj.io/using-firebase-api-with-react/

Sign up to request clarification or add additional context in comments.

2 Comments

React Native actually just released a version that support WebSockets (v. 0.4.4): see github.com/facebook/react-native/releases
Thanks @anuj this was exactly what I was looking for. Works seemlessly.
2

Firebase dev here — as of v0.4.4 of React Native, WebSockets are now supported, and as of version 2.2.5 of Firebase's JS client, we've implemented the integration with React Native. Therefore, Firebase should now work in your React Native app!

There is a known issue with our authentication methods at the moment, but we're working on it.

Let us know if you have any questions!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.