[英]NGRX passing reducer state into components
I have a tasks reducer which represents the following object:我有一个代表以下对象的任务减速器:
{
error: false,
loading: false,
tasks: []
}
Now, the object is passed down into a dumb component:现在,该对象被传递到一个哑组件中:
<task-list tasks="tasks$ | async"></task-list>
The thing I don't like is the fact that to access the list of tasks I have to use tasks.tasks
.我不喜欢的是要访问任务列表,我必须使用tasks.tasks
。 I've considered passing error
, loading
and tasks
into the component separately as well as using getters.我考虑过将error
、 loading
和tasks
分别传递给组件以及使用 getter。 However, this presents another issue when I pass in say tasks
and users
... I'd had to pass in a loading
and error
property for both tasks
and users
但是,当我传入tasks
和users
时,这会带来另一个问题......我必须为tasks
和users
传入loading
和error
属性
Is this an awkward issue that people just accept or is there a better way around this?这是一个人们只能接受的尴尬问题,还是有更好的解决方法?
Are you bothered by tasks.tasks ? 您是否对task.tasks感到困扰?
What's wrong with using a slice of state called tasks
, that would contain 使用称为tasks
的状态片有什么问题?
{
error: false,
loading: false,
currentTasks: []
}
I don't know if you are still looking for an answer, but I always say if something looks intuitively off then it pays off to invest 5 minutes into looking for a better way.我不知道您是否仍在寻找答案,但我总是说,如果某些东西直观地看起来不合适,那么花 5 分钟时间寻找更好的方法是值得的。 Here I would rename the reducer and input:在这里,我将重命名减速器并输入:
<task-list state="taskListState$ | async"></task-list>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.