I'm talking about the mapStateToProps
argument of connect
.
One of my components has a property called rules
which is an array of functions. In mapStateToProps
I invoke those rules, passing in the current state. The rules either return an error message or true
if there is no error. I put these error messages into a new prop so that the final component receives an array of error messages instead of an array of functions.
So far this has been working great, but now I want to add support for asynchronous rules. My plan right now is that whenever a rule returns a Promise instead of an error string, I will push a message like "Checking..." into the array of error messages instead, but once the promise is settled I need to "refresh" this array and insert the resolved message.
I figure if I can force an update then redux will have to call mapStateToProps
again. In such a case, all the rules would be re-evaluated, but if I'm not careful I would receive a new Promise which would put right back to square one. However, if I memoize these rules then I can get back the same Promise instance as before, and then check if it's settled and then put that value into my error array instead.
So now the only problem is figuring out how to get a reference to the component instance within the context of mapStateToProps
which only has access to the current state and props.
Is there any way I can force a re-render once my Promise has resolved?
Alternatively, if I could dispatch
an action when it's resolved, I could work with that as well.