从 redux-saga 调用重新选择选择器
call reselect selectors from redux-saga
我试图通过将视频 ID 传递给选择器来从 redux-saga 调用组合选择器
import { createSelector } from 'reselect';
const selectVideoStore = state => state.video;
export const selectVideos = createSelector(
[selectVideoStore],
video => video.videos
);
export const selectVideosForPreview = ytid =>
createSelector(
[selectVideos],
videos => (videos ? videos[ytid] : null)
);
const selectedVideo = yield select(selectVideosForPreview, ytid);
console.log({ selectedVideo });
这个 returns selectedVideo
中的函数
您的 selectVideosForPreview
不是选择器,而是选择器工厂。所以你需要在将它传递给 yield select()
:
之前创建一个选择器
const selectedVideo = yield select(selectVideosForPreview(ytid));
我试图通过将视频 ID 传递给选择器来从 redux-saga 调用组合选择器
import { createSelector } from 'reselect';
const selectVideoStore = state => state.video;
export const selectVideos = createSelector(
[selectVideoStore],
video => video.videos
);
export const selectVideosForPreview = ytid =>
createSelector(
[selectVideos],
videos => (videos ? videos[ytid] : null)
);
const selectedVideo = yield select(selectVideosForPreview, ytid);
console.log({ selectedVideo });
这个 returns selectedVideo
您的 selectVideosForPreview
不是选择器,而是选择器工厂。所以你需要在将它传递给 yield select()
:
const selectedVideo = yield select(selectVideosForPreview(ytid));