问题标签 [reselect]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
379 浏览

angular - 为什么在重新选择重构后,ngrx 应用程序中的状态现在未定义?

我刚刚浏览了我以前工作的应用程序并将其重构为使用重新选择,就像现在的 ngrx 示例应用程序一样。我没有任何编译错误,但我有这个运行时错误:

从我的session.reducer.ts文件中的这段代码

这是在主应用程序页面中用于显示/隐藏登录用户名的标志。该页面几乎完全空白,我遇到了与未定义状态的其他部分相同的问题。我不确定要尝试什么。

0 投票
0 回答
236 浏览

reactjs - 在 React/Redux 中使用 reselect

我有一组通过容器组件使用中央存储(即 redux 存储)的组件。这些组件往往是简单的并且驻留在 HOC 组件中。HOC 组件使用react-redux connect

上面分别是子组件Component1和 Component2的选择器。

下面是使用reselect的选择器的外观。

问题是重新选择的正确用法我注意到这是无效的,因为如果我的 HOC其他选择器触发了Component1 Component2无论如何也会被重新渲染。我应该检查shouldComponentUpdate方法中的每个数据流。我认为重新选择使用将首先解决这个问题。我误会了吗。它只是防止重新计算部分吗?

这是我之前的帖子的延续, 防止在 redux 中触发子组件的选择器

0 投票
2 回答
927 浏览

reactjs - 重新选择记忆忽略不相关的更新

按照重新选择文档上的示例:

在典型的 redux 应用程序中,subtotalSelector如果用户更新,将重新计算item.name,即使这对结果没有影响。有没有办法避免这种情况?

0 投票
4 回答
3265 浏览

javascript - 未定义状态重新选择 Js

我收到以下错误:substate is undefined。但是,我不确定为什么substate在我的选择器中未定义。有人可以帮我弄清楚可能出了什么问题吗?

选择器:

0 投票
1 回答
218 浏览

reactjs - 重新选择,我在哪里放置计算派生数据逻辑?

最近,我开始学习reselect,并尝试在我的项目中使用它。

但是,我怀疑我应该把计算派生数据的代码放在哪里。

下面是我的代码片段,我想我把formatDate calcDayLeftFromNow setDeriveData逻辑放到我的reducer也可以。

我做派生数据计算reducer也可以。

如果我这样做,似乎没有理由使用reselect.

0 投票
1 回答
338 浏览

reactjs - 使用 ImmutableJS 访问 ReactJS 中的选择器值

我正在通过 react reselect 库使用记忆选择器,并且在访问状态值以查看它是否已设置时遇到问题。

我希望能够做这样的事情来检查:

商店长这样:

这是什么mapStateToProps(这部分正在工作),我的选择器看起来像:

选择器:

当我做

我得到了一个函数,但我无法得到我正在寻找的值。我认为这是因为我正在使用createSelector但我不确定。有谁知道我如何访问选择器的值?

0 投票
3 回答
10238 浏览

javascript - 状态如何传递给 react-redux 应用程序中的选择器?

我遇到了一个示例,其中 mapStateToProps 函数正在使用记忆。我只是想知道如何将“状态”参数传递给记忆选择器。在查看了 reselect 和 redux 的文档之后,似乎 mapStateToProps 可以返回一个接受状态作为其参数的函数,并且连接装饰器可能是将状态传递给它但不确定的那个。有人可以阐明一下吗?

意见/曲目列表/index.js

核心/tracklists/selectors.js

0 投票
2 回答
566 浏览

javascript - Rendering a component based on dynamic route params with mapStateToProps and reselect

I am storing data for various rooms in a global app container. I have a sub-container called roomDetails that uses a reselect selector to select a room from the global state using ownProps.params.slug. This is done using mapStateToProps.

My problem is that when I change route params (rooms/:roomId) from:

rooms/roomid1

to

rooms/roomid2

the component room props are not updating.

I'm changing the route using Link:

<Link to={"/room/roomid1"} key={"room-roomid1"}>room 1</Link>

How can I get the component's room props to reselect a room from the global rooms state when the route params change?

Note, the room props load as they should on first page load, or if i go to a route that's outside of the dynamic route, and then return. They just don't load correctly when switching between the same dynamic route, where only component properties (route params) are changing.

RoomDetails/index.js

...

selectors.js

0 投票
2 回答
2098 浏览

redux - 比较和对比 redux reselect vs lodash / underscore memoize ...?

我想知道是否有人可以比较和对比 redux reselect lib 与 lodash memoize 之间的差异......?

0 投票
1 回答
1085 浏览

reselect - substate.get() 不是使用 React Boilerplate 的函数

我有一个名为 Login 的组件,以及这些选择器:

以下是“登录”组件的状态:

在另一个组件中,我想选择“用户”对象。

在我的文件顶部,我有

当我使用“selectUser()”时,我得到“loginState.get 不是函数”。

如果我删除对“selectUser()”的所有引用,我可以访问 this.props.login.user。这对我有用,但我想知道为什么我不能从“登录”状态中选择。这些示例在选择器中使用相同的“子状态”约定,并且它们有效。有任何想法吗?