如何使用功能组件和react-redux退订Firebase?

时间:2020-07-24 04:00:53

标签: reactjs firebase react-native react-redux

任何人都有任何示例,如何针对使用功能组件的React Native应用程序使用react-redux取消从firebase的onSnapshot预订?

1 个答案:

答案 0 :(得分:0)

您需要从useEffect析构函数回调中调用unsubscribe方法。

public class MyClass
{
    public ReadOnlyCollection<ReadOnlyMyItem> MyItems { get => GetMyItems(); }
    private List<MyItem> myItems;
    // ...

    private ReadOnlyCollection<ReadOnlyMyItem> GetMyItems()
    {
        throw new NotImplementedException();
    }
    // ...
}

public class MyItem
{
    // ...
}

public class ReadOnlyMyItem
{
    private readonly MyItem myItem;
    // ...

    public ReadOnlyMyItem(MyItem myItem) => this.myItem = myItem;
    // ...
}