react-native-router-flux: Actions.callback is not defined!
Version
- react-native-router-flux v3.22.8
- react-native v0.24.0-rc5
Issue
I’d expect that as soon as the Router is rendered, Actions has a callback for all scenes to transition to.
In my app I tried to transition to a login scene if the user isn’t logged in at start. However, I get an error as soon as Actions.login() in the componentDidMount() function is executed:
Actions.callback is not defined!
If I try to do the same from within the Main.componentDidMount() function it works as expected.
At which point are the Scene callbacks added to Actions? Am I doing it wrong?
const reducerCreate = params => {
const defaultReducer = Reducer(params);
return (state, action) => {
console.log('ACTION:', action);
return defaultReducer(state, action);
};
};
componentDidMount() {
if (!loggedIn()) {
Actions.login();
}
},
render() {
return (
<Router createReducer={reducerCreate}>
<Scene key="root" hideNavBar>
<Scene key="login" component={Login} />
<Scene key="main" component={Main} initial />
</Scene>
</Router>
);
}
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 31 (10 by maintainers)
Commits related to this issue
- V4 announcement, v3 is obsolete now; closes #1,#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12,#13,#14,#15,#16,#17,#18,#19,#20,#21,#22,#23,#24,#25,#26,#27,#28,#29,#30,#31,#32,#33,#34,#35,#36,#37,#38,#39,#40,#41,#... — committed to aksonov/react-native-router-flux by aksonov 7 years ago
- V4 docs; closes #1,closes #2,closes #3,closes #4,closes #5,closes #6,closes #7,closes #8,closes #9,closes #10,closes #11,closes #12,closes #13,closes #14,closes #15,closes #16,closes #17,closes #18,cl... — committed to aksonov/react-native-router-flux by aksonov 7 years ago
Is this fixed? I don’t understand what I should do to get over this? Where is the right spot to call Actions.methods… ? If not in componentDidMount? where?
Thanks Much
@shilpan the callback is an excellent idea. Or a promise would work too. And yes, I’m using an arbitrary timeout as well (1 second). Obviously far from ideal.