在 Firebase React-Native 应用程序中按名称删除项目

Remove item by name in Firebase React-Native app

我正在尝试 remove/delete 我的 Firebase 数据库中的项目 onPress 一个按钮。以下是我用于尝试删除该项目的方法的代码。

let itemsRef = db.ref('/items');

handleRemove = (item) => {

    itemsRef.remove({
      name: item
    });
}

我的 remove 方法与将项目添加到数据库的 push 方法的实现相同。

我收到一条错误消息 - "Error: Reference.remove failed: first argument must be a valid function"

See image of error screen

remove 方法不将对象作为参数。你应该只这样做:

itemsRef.remove();

来自文档:

remove

remove(onComplete?: function): Promise

Removes the data at this Database location.

Any data at child locations will also be deleted.

The effect of the remove will be visible immediately and the corresponding event 'value' will be triggered. Synchronization of the remove to the Firebase servers will also be started, and the returned Promise will resolve when complete. If provided, the onComplete callback will be called asynchronously after synchronization has finished