向props添加新对象或对象集合

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

我有一个React页面,它从一个使用saga中间件的redux商店加载一堆东西。

在这个特定的页面中,我想加载一些未通过props传递的新内容。

因此,我为新上传的个人资料照片集创建了一个新的reducer,action和watcher。

有没有办法加载这个新的集合,我设置而不将其作为道具传递?

谢谢! :)

这是我对该页面的反应函数:

export default function profileEdit(props) {
    //passed in as props
    const { stats, weapons, armor, readOnly } = props;

    //not passed in as props
    const { profilePics } = ??;

    return (
        <div></div>
    )
reactjs react-redux redux-saga
1个回答
0
投票

你可以使用props或context api传递一些东西来反应组件。

由于你在redux商店中有你的照片,正确的方法是将你的组件包装在connectreact-redux函数包装器中,然后通过mapStateToProps选择集合。

这样,来自redux商店的数据将被注入到组件的道具中,以便您可以显示它们。

这是一个例子:https://gist.github.com/markerikson/121c77a01c453466361a9c6434a08620

© www.soinside.com 2019 - 2024. All rights reserved.