React-native-router-flux: Receiving "synthetic event is reused" warning when navigating between scenes using redux sample code

Created on 27 Oct 2016  路  11Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux v3.36.0
  • react-native v0.35.0

Expected behaviour

Navigating from one scene to another using the redux example should work without React performance warning

Actual behaviour

Receiving the following warning when navigating between scenes using the sample code provided: "Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property "type" on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist()."

Steps to reproduce

  1. Implement the sample code for redux found here, including the following in your first component:
<Text onPress={Actions.home}>Go home</Text>
  1. Run the app and tap on Go home
  2. App is directed to home view, but several warnings appear with the text above

glass_and_iphone_6s_ _ios_10_0__14a345_

Most helpful comment

@joeferraro @Almouro - I've found that changing from

onPress={Actions.otherScene}

to

onPress={() => Actions.otherScene()}

has removed with these errors.

All 11 comments

@joeferraro I'm also seeing this - did you have any luck figuring out what was going on?

I'm seeing the same thing :\

@joeferraro @Almouro - I've found that changing from

onPress={Actions.otherScene}

to

onPress={() => Actions.otherScene()}

has removed with these errors.

Thanks @jamielob, this was the problem for me too. :)

Thanks @jamielob.

I wonder why the mini tutorial uses onPress={Actions.Foo} instead. Could there be a reason for that?

screen shot 2017-01-30 at 4 14 27 pm

jamielob's suggestion fixed the error for me.

Noob here though, what's going on differently under the hood when you pass it an anonymous function vs an actual reference.

In case anyone else comes across this error and the above doesn't work, I encountered it because I was passing the first argument from onSubmitEditing on a <TextInput> to a function like so:

<TextInput
  onSubmitEditing={(text) => this.performSearch(text)} // Should be event, not text
/>

That text variable is actually the submit event which is what ended up giving me the message above and a headache debugging for a while.

event.preventDefault();
event.stopPropagation();

I think the problem is, you're trying to access the event object after it's released and redefined.

React Docs => The SyntheticEvent is pooled. This means that the SyntheticEvent object will be reused and all properties will be nullified after the event callback has been invoked. This is for performance reasons. As such, you cannot access the event in an asynchronous way.

if you need to use an attribute from the event obj then you would have to access it like this

function displayForm(event){
    console.log(event) // will error
    console.log(event.type) will work
    const eventType = evnet.type; 
   // or call event.persist();

If you want to access the event properties in an asynchronous way, you should call event.persist() on the event, which will remove the synthetic event from the pool and allow references to the event to be retained by user code.

I'm not sure if the cause of this issue has been clearly explained, so please allow me to share my understanding and how I fixed it.

TouchableWithoutFeedback defines onPress?: (event: GestureResponderEvent) => void;.

Thus, when providing simply the function name, the parameter that is passed in is a GestureResponderEvent - and there's a good chance that isn't what you expect.

By changing from the function name to an anonymous function that invokes your function (eg () => yourFunction()), the GestureResponderEvent is not passed through to your function.

Guys i had this problem on a navigator.

Screen.navigationOptions=({navigation})=>{
const handleEditButton=navigation.navigate.bind(this,"EditProduct")
return {
    headerTitle:"My Products",
    headerRight:<CustomHeaderButton 
    iconName="ios-add"
    title="Add"
    iconSize={26}
    color={colors.bright}
    onPress={handleEditButton}
    />
}
}

pay attention to the method i used . I was trying to bind the navigate method. (Yeah, i know)

const handleAddButton=()=>navigation.navigate("EditProduct")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maphongba008 picture maphongba008  路  3Comments

moaxaca picture moaxaca  路  3Comments

sylvainbaronnet picture sylvainbaronnet  路  3Comments

xnog picture xnog  路  3Comments

GCour picture GCour  路  3Comments