简单计算不接受输入
Redux 库 easy-peasy 有一个名为 compulated
的函数,它是标准 Redux 选择器的替代方案:
import { computed } from 'easy-peasy'
const model = {
session: {
totalPrice: computed(state => state.price + state.tax)
}
}
然后在组件中调用选择器,如下所示:
import { useStoreState } from 'easy-peasy'
function TotalPriceOfProducts() {
const totalPrice = useStoreState(state => state.products.totalPrice)
return <div>Total: {totalPrice}</div>
}
问题是,似乎没有将输入传递给选择器的方法。如果我需要该状态的数组中的特定对象,我无法将该对象的 ID 作为输入传递。我唯一的选择是在组件方面执行此操作。 Redux 选择器的优点是函数,因此我可以传递要在选择器逻辑中使用的输入。
有人使用 easy-peasy 之前遇到过这个问题吗?
The Redux library easy-peasy has a function called computed
which is an alternative to standard Redux selectors:
import { computed } from 'easy-peasy'
const model = {
session: {
totalPrice: computed(state => state.price + state.tax)
}
}
And then the selector is called in the component like this:
import { useStoreState } from 'easy-peasy'
function TotalPriceOfProducts() {
const totalPrice = useStoreState(state => state.products.totalPrice)
return <div>Total: {totalPrice}</div>
}
The problem is that there doesn't seem to be a way to pass inputs to the selector. If I need a specific object in an array in the state, I can't pass the ID of the object as an input. My only option is to do this on the component side. Redux selectors have the advantage of being functions, so I can pass inputs to be used in the selector logic.
Anyone use easy-peasy come across this problem before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要启用此功能,您必须返回 作为您的计算属性。
这是一个示例,公开了一个计算函数
getTodoById
:To enable this, you have to return a function as your computed property.
Here is an example, exposing a computed function
getTodoById
:Then you can use it like this: