Reputation: 514
I send data to my API and then call the page DataManifest.js
On this page I just call the import { Actions } from 'react-native-router-flux';
And I have a button that when clicked will go to index.js
page
<Button
onPress={ Actions.index() }
title="Return"
color="#841584"
/>
However, when loading the page it calls directly to index.js
without clicking the button
And returns the following debugger warning:
Warning: Cannot update during an existing state transition (such as within
render
or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved tocomponentWillMount
.
Upvotes: 0
Views: 1086
Reputation: 1977
Think about what onPress is. It is a function. You need to pass it a function. What you was originally passing was the result of running that function. You don't want to pass the result of running the function, you want a function. So you would pass onPress={Actions.index}
. If you needed to manage the parameters you call the function with, then you can wrap it in another function and manage it that way. Like the other answer suggests onPress={ () => { Actions.index() } }
. But you see, that is returning a function, not the result of running a function.
Upvotes: 3
Reputation: 3219
From
onPress={ Actions.index() }
To
onPress={ () => { Actions.index() } }
Upvotes: 1