I'm using immutableJS, React/Redux and I have this map and I need to get the values of actions
, so it will be like -> allRetrospectivesMap
-> id
-> current_stage
-> actions
I have this code and it works, but it's super ugly, is there a better way to do it?
class UserActionItems extends Component {
render() {
const { retrospectives } = this.props
const actions = flatten(
Object.keys(immutableHelpers.toJS(retrospectives))
.map(key => retrospectives.get(key))
.map(retro => immutableHelpers.toJS(retro.getIn(['current_stage', 'actions'])))
).value()
return (
<div>
<ActionsList
actions={actions[0]}
users={[]}
/>
</div>
)
}
}
const mapStateToProps = ({ allRetrospectivesMap }) => ({
retrospectives: allRetrospectivesMap
})
Thanks!!! :)
You can do this with a getIn()
method from immutable js.
const id = getId() // you've id from somewhere
const actions= state.getIn(['allRetrospectivesMap', id, 'current_stage', 'actions']); // Note: state is your immutable data.
Read more about it here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.