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

[🐛] When migrating to the new API, what replaces database.ServerValue and storage.TaskState #8329

Open
nes123 opened this issue Feb 13, 2025 · 8 comments
Labels

Comments

@nes123
Copy link

nes123 commented Feb 13, 2025

I get these warnings:

This v8 method is deprecated and will be removed in the next major release as part of move to match Firebase Web modular v9 SDK API. Please use getApp() instead.

I migrated most of the methods but didnt find a replacement to database.ServerValue and storage.TaskState

@mikehardy
Copy link
Collaborator

I believe this is fixed with the just-merged-this-morning #8322 - set to release shortly with the storage module types you need correctly importable at top level from the our modular implementation exports

@nes123
Copy link
Author

nes123 commented Feb 13, 2025

I believe this is fixed with the just-merged-this-morning #8322 - set to release shortly with the storage module types you need correctly importable at top level from the our modular implementation exports

Great, thanks! We need similar thing for the database right?

@russellwheatley
Copy link
Member

russellwheatley commented Feb 13, 2025

Database is a bit different, we didn't port over the statics because there is another way of getting the timestamp. Call this function: https://github.com/invertase/react-native-firebase/blob/main/packages/database/lib/modular/index.js#L111

which is the firebase-js-sdk way of retrieving it.

e.g.

import database, { serverTimestamp } from '@react-native-firebase/database';
// namespaced - deprecated way
const timestamp = database.ServerValue.TIMESTAMP;

// modular - latest way
const timestamp = serverTimestamp();

@nes123
Copy link
Author

nes123 commented Feb 13, 2025

Database is a bit different, we didn't port over the statics because there is another way of getting the timestamp. Call this function: https://github.com/invertase/react-native-firebase/blob/main/packages/database/lib/modular/index.js#L111

which is the firebase-js-sdk way of retrieving it.

e.g.

import database, { serverTimestamp } from '@react-native-firebase/database';
// namespaced - deprecated way
const timestamp = database.ServerValue.TIMESTAMP;

// modular - latest way
const timestamp = serverTimestamp();

Thank you. I dont need the TimeStamp..I need ServerValue.increment()

@russellwheatley
Copy link
Member

You need to use this function then: https://github.com/invertase/react-native-firebase/blob/main/packages/database/lib/modular/index.js#L120

import database, { increment } from '@react-native-firebase/database';
// namespaced - deprecated way
const incrementUpdate = database.ServerValue.increment(1);

// modular - latest way
const incementUpdate = increment(1);

@nes123
Copy link
Author

nes123 commented Feb 16, 2025

In the new version, there seems to be a new problem.

export function serverTimestamp() {
  return firebase.database.ServerValue.TIMESTAMP;
}

/**
 * @param {number} delta
 * @returns {object}
 */
export function increment(delta) {
  return firebase.database.ServerValue.increment(delta);
}

"firebase" is not defined in

packages/database/lib/modular/index.js

@mikehardy
Copy link
Collaborator

mikehardy commented Feb 16, 2025

@nes123 what happens if you patch those (that is: editing file directly in node_modules as a test) to read:

export function serverTimestamp() {
  return getApp().database.ServerValue.TIMESTAMP;
}

/**
 * @param {number} delta
 * @returns {object}
 */
export function increment(delta) {
  return getApp().database.ServerValue.increment(delta);
}

firebase. --> getApp().

I haven't tried this, might not work at all, but I think it may fix it

@nes123
Copy link
Author

nes123 commented Feb 16, 2025

It does not work..will it be a mistake to revert and import firebase as before:

import { firebase } from '..';

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

No branches or pull requests

3 participants