Please provide the following:
- SDK Version: 36
- Platforms: Android / iOS
I’m having a hard time working with the BarCodeScanner API. I’m seeing this error when running my app on my Huawei P20 Pro, but I’m seeing the exact same error on the emulator from the expo docs themselves: Link to Snack example.
The error message is: undefined is not an object (evaluating '_ref2.type')
This appears to be triggered when trying to set the state using hooks on line 13 of the linked Snack. I’m not sure if this a specific Expo CLI issue, or is related to react-native itself (I’m very new to hooks). Either way, I can’t see how to resolve this; does anyone have any ideas?
On a slightly unrelated note, what is the purpose of line 11 on the linked Snack? It looks like an incomplete line of code?
Thanks guys
EDIT: To further add to this, I thought perhaps the issue was with passing undefined
on line 37 of the Snack. So, on my local version, I changed this to null and the error disappeared; changing it back to undefined and the error is still fixed. - This does not resolve the issue on the Snack. I’m now even more confused; I don’t know what I’ve changed…
EDIT2: So, I figured it out. I’m not sure if this is a typo in the docs, or if there’s something else missing. When you specify the function to call onBarCodeScanned
, you shouldn’t include the parenthesis ()
. So changing line 37 on the snack from
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned()}
to
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
resolves the error. I guess this is the right way to do things, because it just worked now; but can anyone confirm why the docs have the parenthesis? Is it a typo? Am I missing something else?