reactjs - Robust way to handle app errors inside mapStateToProps? -
i'm looking advice on robust , reliable way handle errors within mapstatetoprops, , if it's advisable attempt @ level within react+redux app.
for example, if use react-redux's connect component , mapstatetoprops:
function mapstatetoprops(state, ownprops) { throw error('some unfortunate error.'); return { // data } } i want catch error , maybe display error component in place of rendering component. not make attempt recover - pick , move on.
at moment i've noticed stalls react completely, , page need reloaded: uncaught typeerror: cannot read property 'gethostnode' of null
i handle exception regular data since connect still expect props pass them component. i'd this:
function mapstatetoprops(state, ownprops) { try { // code return { // data } } catch (e){ return { error: e } } } and have component props.error , display error message.
Comments
Post a Comment