I can't do map() function for rendering because the length of the array is always 0, even though I get data from the array. Is there a way to set time interval until the asynchronous array is loaded properly?
This is mine code:
function ShortcutComponent({ usershortcuts }) {
console.log(usershortcuts); // I get an array
console.log(usershortcuts.length); //I get 0
return (
<Button ui="headerButton" arrow={false} ripple={false} iconCls="icon-directions" border={false} handler={() => this.loadData()}>
<Menu title="Shortcuts">
{usershortcuts.map((item) => {
<MenuItem key={item.id} iconCls={item.shortcutDefinition.iconCls} text={item.shortcutDefinition.description} />
}
</Menu>
</Button>
)
}
const mapStateToProps = (state) => {
return {
usershortcuts: state.usershortcuts
}
};
const mapDispatchToProps = (dispatch) => {
return {
actions: bindActionCreators(usershortcutAction, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps) (ShortcutComponent);
As a evidence here is the picture: