gpt4 book ai didi

redux - 如何将函数保存到 Redux 存储?

转载 作者:行者123 更新时间:2023-12-02 01:14:17 25 4
gpt4 key购买 nike

我想将一个函数(引用)保存到我的 Redux 存储中,这样我就可以:

  1. 将函数引用传递给连接到存储状态的组件,或者
  2. 检索存储的函数并在 action creator 中运行它。

普遍的共识似乎是您不应该在 Redux 存储中存储函数引用(因为数据应该是可序列化的)。有什么方法可以解决这个问题,从而实现上述两个过程?

最佳答案

根据 Redux FAQ entry on non-serializable items in state :

It is highly recommended that you only put plain serializable objects, arrays, and primitives into your store. It's technically possible to insert non-serializable items into the store, but doing so can break the ability to persist and rehydrate the contents of a store, as well as interfere with time-travel debugging.

If you are okay with things like persistence and time-travel debugging potentially not working as intended, then you are totally welcome to put non-serializable items into your Redux store. Ultimately, it's your application, and how you implement it is up to you. As with many other things about Redux, just be sure you understand what tradeoffs are involved.

关于redux - 如何将函数保存到 Redux 存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43443110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com