是否可以为List组件定义自定义传奇?我的意思是,在安装列表时,它会调度动作RA/CRUD_GET_LIST
,该动作自动(由于从父级组件传递下来的道具)从服务器获取数据。我想用不同的行为定义自己的RA/CRUD_GET_LIST
,可以吗?
列表组件:
<List
{...this.sanitizeProps(this.props)}
filter={{ userId: userId }}
title="History"
perPage={10}
>
<DataGridComponent />
</List>
使用sanitizeProps
过滤所需的道具,然后传递其他道具。
我需要等待的资源是:<Resource name="user" />
我从我的定制减速器中获得了userId
:
const mapStateToProps = state => ({
userId: state.userReducer.user.id
});
答案 0 :(得分:1)
要回答您的问题,不,不可能。但是,您可以通过将List包裹在连接的组件中并只有当具有user_id时才呈现List
来实现所需的结果。否则,仅返回null或表明您正在加载内容的内容。
const MyConnectedList = ({ userId, ...props }) =>
userId
? (
<List
{...this.props}
filter={{ userId }}
title="History"
perPage={10}
>
<DataGridComponent />
</List>
)
: null