console.log(data)
reveals the following:
(4) […]
0: "a19870e84cc92abeb5904fccd1f74329"
1: "12793d4229b32a0b1fc387e041ed7be8"
2: "12793d4229b32a0b1fc387e041ed7be8"
3: "5fec6cd9e7c78a4a985d1f5b82f05280"
length: 4
Yet, console.log(data.length)
says the following:
0
..and indeed, I'm unable to loop through the array with a for
loop because data.length = 0
.
How can my array have 4 elements but have zero length all at once? I'm confused.
ps. the array gets produced via an async' redux function, here:
export const getFiles = () => {
return async (dispatch: AppDispatch, getState: Function) => {
const state = getState()
const scriptAddress = state.chainInfo.data.scriptAddress
var fileData: string[] = []
api.cmd("coins;", function(respJSON: any) {
if( api.util.checkAllResponses(respJSON) ) {
//console.log(respJSON)
const coins = respJSON[0].response.coins
for ( let i = 0; i < coins.length; i++ ) {
if (coins[i].data.coin.address == scriptAddress) {
fileData.push(coins[i].data.prevstate[0].data)
}
}
}
})
dispatch(write({data: fileData})(GetActionTypes.GET_SUCCESS))
}
}
And it updates a react component via mapStateToProps
- so it only gets the data after the async operation has updated the store via a reducer
. So I don't 'think' it's an async
problem.
And gosh - I should've mentioned all the react, redux, mapState stuff. Sorry!