0

I'm simply trying to access the x coordinate through the onLayout prop within a TouchableOpacity component in React Native and I'm getting an error in the emulator:

null is not an object (evaluating 'event.nativeEvent.layout')

This is my first time dabbling into the React animation side of things and have no idea why it's failing. There also doesn't seem to be much online about it so I'm starting to think it's been deprecated.

<TouchableOpacity 
   onLayout={(event) => this.setState(prevState => ({ 
       tabs: { ...prevState.tabs, xTabOne: event.nativeEvent.layout.x } 
   }))}
/>
halfer
  • 19,824
  • 17
  • 99
  • 186
Chris Marshall
  • 740
  • 1
  • 9
  • 25
  • After looking at the documentation even though the emulator isnt complaining about the onLayout prop it doesnt seem to be listed in the documentation for react naive – Chris Marshall Aug 01 '20 at 15:20

1 Answers1

1

So interestingly when I remove the prevState part of the setState the value can be found so I'm assuming this is some scope issue with the set state function.

Chris Marshall
  • 740
  • 1
  • 9
  • 25