gpt4 book ai didi

reselect - 创建采用动态参数的重新选择选择器时出现问题

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

我正在尝试将动态参数传递给重新选择选择器。这样做的原因是这个参数实际上是一个事先不知道的角度路线参数。它也不能是国家的一部分。

以下是来自订阅组件的传递路由参数的相关代码:

this.store.select(fromRoot.getMessagesWithOtherUserAccount(this.route.params['otherId']))
.subscribe(messages => this.messagesWithOtherUserAccount = messages);

这是选择器的代码:

const getMessagesState = (state: State) => state.message.messages;

//See error below... How can I pass my otherId argument here??
const messagesWithOtherUserAccount = createSelector(getMessagesState, messagesWithCounterParty);

export const getMessagesWithOtherUserAccount = (otherId: number) => messagesWithOtherUserAccount(otherId);

....
export const messagesWithCounterParty = (messages: Message[]) => (otherId: number) => withOtherUserAccount(otherId, messages);

这是我得到的错误:

Argument of type 'number' is not assignable to parameter of type 'State'.

我想将 otherId 参数传递给 messagesWithOtherUserAccount createSelector,但我不知道如何...

有人可以帮忙吗?

最佳答案

我能够想出以下解决方案:

this.store.select(fromRoot.getMessagesWithCounterParty(this.route.snapshot.params['otherId']))
.subscribe(messages => this.messagesWithOtherUserAccount = messages);

export const getMessagesWithCounterParty = (otherId: number) => createSelector(getMessagesState, (messages: Message[]) => withOtherUserAccount(otherId, messages));

关于reselect - 创建采用动态参数的重新选择选择器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43474874/

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