Skip to content
Advertisement

Can’t find variable: counter, in expo

Been using React for a bit and wanted to try out native using expo, when I click on a button to increment a counter, I get a ReferenceError on my phone saying “Can’t find variable: counter”, I don’t get any error on the expo gui or in VSCode, very confused.

JavaScript

Advertisement

Answer

Change your increment function to

JavaScript

Make sure to define your increment function as an arrow function otherwise you can’t access it from Button.

JavaScript

Feel free for doubts.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement