react-native-router-flux throws Actions.callback is not defined -


running following snippet results in router throwing

import react 'react'; import {scene, router} 'react-native-router-flux';  export default app extends react.component {   componentdidmount() {       // fails       actions.login();   }    render() {     return (       <router>         <scene key="root" hidenavbar>           <scene key="login" component={login} />           <scene key="main" component={main} initial />         </scene>       </router>     );   } } 

the router should have been mounted app.componentdidmount, actions supposed working.
if set timeout 2 seconds, work. has ran it? doing wrong here?

so understood problem is.
problem not scenes taking time initialize.
action.login needs have actions.callback router injects after first actual render after root componentdidmount.

here's happens:
root render function called
router render function called without state.reducer nothing.
router componentdidmount called - here actions initialized , reducer gets saved state (setstate async).
root componentdidmount - here callback still not initialized.
router render called - call triggered setstate before. actions.callback injected.

so after second render, router initialized.

i managed find better solution arbitrary settimeout.
override router render method, , right after it's rendered data, notify parent:

class overriderouter extends router {     constructor(props) {         super(props);         this.render = this.overriderender;     }     overriderender() {         const result = super.render();         if (!result) {             return result;         }         // after first initialization use regular render.         this.render = super.render;         if (this.props.onrouterinitialize) {             // need settimeout allow method complete actions.callback populated             settimeout(this.props.onrouterinitialize, 10);         }         return result;     } } 

edit
managed fix problem entirely , sent pull request solve it. https://github.com/aksonov/react-native-router-flux/pull/1137


Comments