我需要访问我的容器内的redux状态的特定属性。这些属性反过来将被用作获取其他嵌套属性并将它们映射到组件道具的关键。我使用immutableJS。访问mapStateToProps中的状态属性
是在mapStateToProps内部执行此操作的最佳方法吗?这是否会导致任何性能开销或是否正常,因为mapStateToProps已经接收整个状态作为参数?
下面是一个例子。
状态选择:
export const userSettingsState = state => state.get('userSettings');
export const transactionsState= state => state.get('transactions');
userSettings是不可变的地图和交易也是一个Map,用户ID和事务列表对。
const mapStateToProps = (state) => {
const curUID = userSettingsState(state).get('currentUserID');
return {
trList: transactionsState(state).getIn([curUID, 'trList'])
};
};
我需要currentUID来访问用户事务。上述示例工作正常。但这是最好的方法吗?