text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
And so let's play with that a little bit.
2,372.31
2.89
So first let's copy this, that way you can keep it.
2,375.2
3.81
So let's clear all of this and then play with mounting a little bit.
2,389.01
8.76
And so in your next project what you're going to do is you're
2,397.77
3.27
going to be implementing what's called a Pomodoro timer.
2,401.04
3.76
And so for those of you who are aware of what those are--
2,404.8
3.47
basically what it is is a timer that allows you
2,408.27
3.06
to switch between two amounts of time.
2,411.33
3.069
And so there's this thing called the Pomodoro Technique which
2,414.399
2.541
is used for studying where you study or work very hard for some amount of time
2,416.94
4.187
and then you take a short break.
2,421.127
1.333
And then you work hard for some short amount of time
2,422.46
2.166
and then you take a short break.
2,424.626
1.605
And so what you're going to be creating in your next project
2,426.231
2.499
is actually a timer that allows you to do that.
2,428.73
2.46
It will automatically track for you however long you want to work.
2,431.19
4.79
And it will also allow you to set some time
2,435.98
2.227
that you want to take a break in between those working blocks.
2,438.207
2.583
And it will do that.
2,440.79
0.833
So when you start the timer it will count down until you're done working.
2,441.623
3.787
It will let you know, hey time for a break.
2,445.41
2.28
Then it will switch over to that break timer,
2,447.69
1.98
run down until that ends up and says, oh now it's time to work,
2,449.67
3.12
and it will cycle through that.
2,452.79
1.82
And so in order to do that, you might need
2,454.61
1.75
to know how to work things like timers.
2,456.36
2.85
And so these methods may be a chance for you to set up those timers.
2,459.21
5.41
And so let's go ahead and do an example doing that.
2,464.62
3.08
So first let's get rid of all of this stuff.
2,467.7
6.22
So in this example we no longer need TODOs.
2,473.92
4.27
And in our render lets actually just have some count.
2,478.19
4.88
Those have a View.
2,483.07
0.75
And inside here let's have some text.
2,488.62
1.96
And that text is just going to show some count.
2,496.27
2.1
And let's initialize that count to 0.
2,505.04
1.67
So, as soon as I get rid of all this, we have a very simple app and all it does
2,515.55
5.31
is show a count of 0.
2,520.86
1.07
You see it up in this left hand corner here.
2,521.93
2.49
And let's go ahead and actually center this.
2,524.42
1.88
So let's do styles, and let's create a new style sheet.
2,526.3
6.74
Let's call this app container and whatever we want to do in here.
2,537.42
3.91
So let's have it grow as much as we can.
2,541.33
2.719
Let's have it center its items.
2,544.049
1.291
And let's have it align its items the other direction as well.
2,549.69
4.95
And down here let's actually pass this in as styles.appcontainer.
2,562.24
4.76
So now we see this number 0 is very small.
2,573
1.97
Let's go ahead and make it a little bit bigger.
2,574.97
2.73
And so let's have count and let's give it a big font
2,577.7
4.65
size of like 48 or something.
2,582.35
3.669
So now-- style--
2,592.87
4.94
we have a big number and all it does is 0.
2,597.81
2.16
And so how are we going to get it to count?
2,599.97
2.43
Well presumably we should be setting our state
2,602.4
2.25
and just have that state increase.
2,604.65
4.05
And so if we want to repeat something what might we use to achieve that?
2,608.7
5.69
So do something at some given interval.
2,618.21
3.81
We can actually use that set interval.
2,622.02
2.83
And so let's first implement this count.
2,624.85
2.2
So let's have this thing called increment.
2,627.05
2.1
Is this too small?
2,629.15
3.44
Let's have this thing called ink.
2,632.59
2.05
And what that does is it does this.setstate, takes a previous state
2,634.64
8.81
and returns the count to be 1 greater than the previous state.
2,643.45
4.74
And so now we've implemented this thing called increment where we
2,653.45
4.77
take the states count and increment it.
2,658.22
3.25
And so how might we get this increment call to happen every once in a while?
2,661.47
6.497
Well presumably we should use a thing called
2,667.967
1.833
set interval, which we'll call a function every n milliseconds.
2,669.8
4.35
But how are we going to get that to happen?
2,674.15
3.219
Well we should do this after the component finishes mounting.
2,677.369
2.541
We should set up some sort of timer.
2,679.91
2.33
And so how do we know or how do we get a function
2,682.24
2.26
to execute after components finish mounting?
2,684.5
4.73
That's actually where this lifecycle method comes in.
2,689.23
2.519
And so there's this lifecycle method called
2,691.749
1.791
componentDidMount which automatically gets
2,693.54
2.54
run for after the component mounts.
2,696.08
2.63
And so we can actually set up our timer tap in there.
2,698.71
3.38
And so we can do componentDidMount and inside of it we can do setInterval
2,702.09
8.42
and that's called this.Increment every second.
2,710.51
5.58
And so there's going to be a small bug here.
2,716.09
4.56
Does anybody know what the bug is?
2,720.65
3.25
So every 1,000 milliseconds this thing called this.Increment is getting
2,727.08
3.81
called.
2,730.89
1
And this.Increment is invoking this.Setstate.
2,731.89
3.42
Does anybody see how that might be a problem?
2,737.98
3.206
I'll give you a hint.
2,747.15
0.99
It has something to do with this.
2,748.14
4.52
And so when this gets executed this might not mean what this is here.
2,752.66
4.83
And so this is a common bug in React.
2,757.49
1.94
Oftentimes, when you say this here, what it means
2,759.43
4.59
lexically is not necessarily what it means
2,764.02
2.13
when it actually eventually gets run.
2,766.15
2.16
And so how did we go about fixing this bug in previous lectures?
2,768.31
7.06
We have to somehow get this to be bound to what we want it to be.
2,775.37
3.81
And in case we want it to be bound lexically.
2,779.18
4.27
So a few different ways to do that.
2,783.45
1.93
One way was creating a new function here in line that does this.
2,785.38
4.22
And I'm actually not sure that that works in this example
2,793
5.39
because this isn't necessarily set here.
2,798.39
3.18