text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
And it should be the default export. | 4,547.37 | 2.99 |
And so let's take a look
at what that looks here. | 4,550.36 | 2.23 |
And so in app.js in a brand
new directory I went and-- | 4,552.59 | 3.99 |
the boiler plate code says
export this default class app. | 4,559.19 | 3 |
But say I want to in a new file. | 4,562.19 | 2.05 |
So let me create a new file called
let's just call it count.js. | 4,564.24 | 4.09 |
From here let's first import from
React, which is something that we | 4,570.95 | 6.72 |
have to do in every single file. | 4,577.67 | 2.28 |
And let's create this
component called Count. | 4,579.95 | 2.91 |
So let's do const Count
equals props and then | 4,582.86 | 4.2 |
let's return this thing called a view. | 4,587.06 | 2.79 |
And then have props.count show. | 4,589.85 | 5.214 |
Actually, let's have this be text. | 4,595.064 | 1.416 |
So this won't actually work because
we're using this component called | 4,603.81 | 4.53 |
Text here which doesn't exist. | 4,608.34 | 3.15 |
So Text here, capital T
capital Text, is a component | 4,611.49 | 4.68 |
but this file has no idea what
Text is, what capital Text is. | 4,616.17 | 5.33 |
It's a component. | 4,621.5 | 1.64 |
We know it's a component because
it's in JSX and capitalized | 4,623.14 | 3.17 |
but nowhere in this file do we
declare this thing called Text. | 4,626.31 | 3.19 |
And so we actually have to import it
from the library called React Native. | 4,629.5 | 4.49 |
And so you've seen me
before in the example | 4,645.2 | 3.33 |
files do this thing called
import Text from React Native. | 4,648.53 | 2.71 |
And what that the actually does is it
goes into that React Native API code | 4,651.24 | 5 |
and gives you access to the variable
that they're exporting called Text. | 4,656.24 | 3.79 |
And then when we go
ahead and use it here | 4,660.03 | 3.95 |
the JavaScript knows that
this variable context exists. | 4,663.98 | 3.25 |
And so how are we going to get this
component called Count into our app? | 4,667.23 | 7.43 |
So say I wanted to hear a display
count and passed an account of 0. | 4,677.19 | 8.61 |
So if I save this and
try to run it, it's | 4,689.01 | 2.37 |
going to error because this
variable called Count doesn't exist, | 4,691.38 | 5.29 |
which makes sense right? | 4,696.67 | 2.06 |
In this app.js file we haven't
created a variable called Count. | 4,698.73 | 4.59 |
We actually created it in a
separate file called count.js. | 4,703.32 | 5.79 |
And so as I alluded to, you can
actually export a component from a file | 4,709.11 | 3.6 |
and import it into a new file. | 4,712.71 | 2.03 |
And so we can actually, over here,
just use this term called export. | 4,714.74 | 4.285 |
And if we go ahead and
save this then now we | 4,723.05 | 2.62 |
can try to import this
thing called Count from-- | 4,725.67 | 5.115 |
where is it? | 4,734.19 | 0.636 |
Well, it's in the current
directory, so ./Count.js. | 4,734.826 | 2.124 |
And so now if we save that we
can see that it compiles and we | 4,741.21 | 5.85 |
see that 0 show up. | 4,747.06 | 3.39 |
And so let's make it a little bit
bigger so that's easier to see. | 4,750.45 | 3.74 |
And so how are we going to do that? | 4,754.19 | 1.49 |
Let's create this constant called
styles and let's have stylesheet.create. | 4,755.68 | 5.2 |
And let's just have a font size of 72. | 4,765.51 | 5.24 |
And then here let's just do style is
that Styles object that we created. | 4,775.2 | 9.931 |
And if we save this and run
it what's going to happen? | 4,785.131 | 2.249 |
It's going to error. | 4,787.38 | 1.832 |
And why is it erroring? | 4,789.212 | 0.958 |
Well it says cannot find variable called
stylesheet, which makes sense right? | 4,790.17 | 4.04 |
In this file here nowhere is there
a variable called stylesheet. | 4,794.21 | 5.027 |
And so we actually also have to
import that from React Native. | 4,799.237 | 2.583 |
And so if we run that and
save it, lo and behold, | 4,806.19 | 2.53 |
it rhymes and the style is applied. | 4,808.72 | 2.29 |
We see a big number 0 there. | 4,811.01 | 3.41 |
And so that is called a named export. | 4,814.42 | 2.13 |
We exported a named
variable called Count. | 4,816.55 | 4.56 |
And then in here in brackets we say
import all of the variables named Count | 4,821.11 | 6.29 |
that we exported from ./Count.js. | 4,827.4 | 4.48 |
And so that is an example
of a named export. | 4,831.88 | 1.89 |
And say we wanted to export another
named variable we can do export const-- | 4,833.77 | 8.048 |
let's just call it num, and
let's have it be the number 50. | 4,844.954 | 6.936 |
And we can, over here, do import
Count and also num count.js. | 4,851.89 | 5.91 |
And then rather than passing
in 0 we can just pass in num. | 4,857.8 | 4.58 |
And as we see over here
now it's the number 50. | 4,862.38 | 4.13 |
Why is that? | 4,866.51 | 0.69 |
Well in Count.js we
exported two variables. | 4,867.2 | 5 |
One we called Count,
so capital Count here. | 4,872.2 | 3.75 |
We have a const called Count
and we're exporting that. | 4,875.95 | 2.65 |
And so it's a named variable
that's getting exported. | 4,878.6 | 3.09 |
Over here we have a constant called
num, and we're exporting that, | 4,881.69 | 3.42 |
so there's also a named variable
called num that's getting exported. | 4,885.11 | 3.3 |
Then over here in our
app file we actually | 4,888.41 | 2.4 |
import to this thing
called Count and num. | 4,890.81 | 2.589 |
And so the names do
matter because it needs | 4,893.399 | 1.791 |
to know exactly what we're importing in. | 4,895.19 | 2.884 |
And then we go ahead and use those
and they show up as expected. | 4,898.074 | 2.666 |
And so those are called named
imports and named exports | 4,903.57 | 3.32 |
but there's also this thing
called a default export. | 4,906.89 | 3 |
And so you see here we have an
additional term called export default | 4,909.89 | 5.43 |
this value. | 4,915.32 | 1.51 |
And so in our Count file
over here let's get rid of-- | 4,916.83 | 3.55 |
or let's not actually
get rid of anything | 4,920.38 | 1.75 |
and let's actually do export
default. And then just | 4,922.13 | 5.42 |
give it a value to export. | 4,927.55 | 2.94 |
So export default this
function that we're creating | 4,930.49 | 3.6 |
and if we want to make this more
obvious what's happening here | 4,934.09 | 3.03 |
we can actually do
const Count equals this. | 4,937.12 | 7.26 |
And then we can do export
default Count, which | 4,944.38 | 3.45 |
is saying set the default
export of this file to be Count. | 4,947.83 | 3.7 |
And then how are we going to import it? | 4,953.705 | 1.625 |
Well, rather than
importing these name things | 4,955.33 | 4.32 |
we just say we want to import
this thing from Count.js. | 4,959.65 | 5.19 |
And since we've dropped
those brackets we | 4,964.84 | 2.52 |
say just import whatever
is default exporting. | 4,967.36 | 3.14 |
And we're going to call it here Count. | 4,970.5 | 2.62 |
And so if you notice it works-- | 4,973.12 | 3.42 |
oops as long as I save all
the files but I never-- | 4,976.54 | 9.09 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.