Search code examples
react-nativeparameter-passingreact-native-router-flux

React Native - do not stop on page,


I'm new to React Native. I'm trying to send parameters between pages through 'Actions' from react-native-router-flux. 'Actions' is called on 'onPress' method of 'TouchableOpacity'. But the things is that, when I do not give any parameter to 'Actions' it works properly, without any problem. But when I give some parameter, it does not wait on the page, immediately redirects to the new page just like 'TouchableOpacity' is clicked.

Here are both codes with parameter and without parameter.

without parameter

.e

with parameter, do not work properly,don't wait for press, immediatetly navigate when page is rendered


Solution

  • You are exectuing a function instead of giving onPress a function.

    Your first example works because you did not call the function. Calling it with no parameters would be Actions.home(), but you wrote Actions.home which returns the home function.

    Your code should be onPress={() => Actions.home(data.id)} which is simply creating a function for onPress.