从redux-saga调用重新选择选择器

问题描述 投票:0回答:1

我正在尝试通过将视频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 });

这将返回selectedVideo中的函数

reactjs redux redux-saga
1个回答
0
投票

您的selectVideosForPreview不是选择器,而是选择器工厂。因此,您需要先创建选择器,然后再将其传递到yield select()

const selectedVideo = yield select(selectVideosForPreview(ytid));
© www.soinside.com 2019 - 2024. All rights reserved.