Creating a Stopwatch
Some of you that have already worked a bit with JavaScript might think that creating a Stopwatch is as easy as just calling the setInterval()
function and subtracting a number at every iteration. Well, not really, but fear not – we'll make this as easy as possible for everyone, regardless of your experience with JavaScript.
So, let's begin by opening our Stopwatch.js
file, which we can find inside the screens
folder. Right now, there's only some text with the word Stopwatch inside of it that is centered because we styled the main <View />
component.
I'd honestly just start by removing everything from this file and starting fresh with the imports. We'll begin by importing React
, useState
, and useEffect
from 'react'
. After that, we'll import StyleSheet
and SafeAreaView
from 'react-native'
. Finally, we will import the Text
, Block
, and Button
components from 'galio-framework'
.
After importing...