00:00:19.520
hello can you hear
00:00:21.680
me okay so I'm going to talk about
00:00:25.880
reactjs today and I know this is the
00:00:28.439
slot before lunch so awesome lunch is
00:00:31.160
waiting outside for everyone but I hope
00:00:33.719
that you will not react to those
00:00:34.960
Temptations and instead hear me about
00:00:37.360
react so uh I'm on Twitter uh this is my
00:00:40.399
Twitter handle uh I work for big binary
00:00:43.719
we are a ruon rails Consulting shop uh
00:00:46.239
recently we are also doing a lot of
00:00:47.800
reactjs work so uh if you are interested
00:00:50.879
in some work you can contact me later
00:00:53.960
this is my second time in Singapore uh
00:00:56.079
last time I uh came for my first Red Dot
00:00:58.359
Rubicon and I gave my first first hour
00:01:00.359
talk so uh and today I'm more excited
00:01:03.680
because I'm giving my first hour
00:01:05.519
JavaScript talk at a ruby conference so
00:01:08.400
uh I want to thank you the
00:01:11.680
organizers okay so what is react react
00:01:15.799
is a JavaScript UI Library uh that was
00:01:18.520
first developed at Facebook and
00:01:20.400
Instagram uh right now it is open source
00:01:22.680
so everybody can use it it was designed
00:01:25.400
to build large applications which change
00:01:27.840
data over time so that was the main
00:01:31.000
purpose its scope is very limited so
00:01:33.920
it's not like a big framework where you
00:01:35.799
do lot of things it it task its task is
00:01:39.360
to uh only render the UI so only
00:01:42.159
building the UI uh it only concerns with
00:01:46.399
the user interface and so we can't
00:01:49.159
really compare it with a traditional MVC
00:01:51.600
client framework like emberjs or angular
00:01:54.799
J A lot of times uh people can use react
00:01:58.399
as a V part in traditional MVC
00:02:01.399
architecture and that is because it
00:02:03.280
doesn't care about rest of the stack so
00:02:05.560
whatever you using for uh your uh in
00:02:07.920
your existing app you can easily drop in
00:02:10.039
react for some feature try it out if it
00:02:12.520
doesn't work you can uh still go ahead
00:02:14.280
with your uh existing
00:02:17.319
stack react's aim is to be very simple
00:02:21.000
so it it gives developer power to
00:02:23.239
express how their UI will be and rather
00:02:26.480
than uh uh so you you are always talking
00:02:28.840
about what you want rather than how you
00:02:31.400
want so it has a declarative API for
00:02:34.519
doing that and once you declare how your
00:02:37.959
UI will look react will take care of
00:02:40.239
updating rendering and whatever it wants
00:02:42.239
to do with the UI so you just specify
00:02:44.400
how your UI looks like and uh react will
00:02:47.239
uh worry about how to uh render it
00:02:49.720
properly so let's say if I have a video
00:02:53.239
uploading job uh and video is uploaded
00:02:55.879
to some background processing for uh
00:02:57.840
encoding uh in a traditional way what I
00:03:00.200
will do is uh I will PLL like if if the
00:03:03.159
encoding is completed if it is not
00:03:05.680
completed then I will be keep showing
00:03:07.360
the loader message otherwise I will
00:03:09.360
remove the loader so I'm doing something
00:03:11.840
with the Dom I'm removing something or
00:03:14.000
I'm changing the uh header text that
00:03:16.319
encoding is completed in a declarative
00:03:19.159
way what I will do is I will just
00:03:21.040
declare if encoding is completed this is
00:03:23.599
my UI if encoding is not completed this
00:03:26.280
is my UI so react will take care of
00:03:29.159
showing this UI whenever the data
00:03:31.879
changes or whenever the encoding gets
00:03:34.920
completed react also has a lot of
00:03:37.439
unconventional ideas that go against the
00:03:40.000
traditional way of web development so we
00:03:42.080
are doing uh things in a certain way
00:03:44.599
till now and react says that okay these
00:03:47.760
things worked but we want to do things
00:03:50.120
in a different way and it's worth
00:03:52.439
discussing those ideas because that
00:03:54.599
makes react what react is so let's start
00:03:58.079
first we'll discuss uh the components
00:04:01.040
and uh component is just a bundle of
00:04:03.840
HTML CSS JavaScript code put together uh
00:04:07.200
for specifying a certain part of the UI
00:04:10.200
so UI is broken into separate units and
00:04:13.159
each unit specifies a component uh this
00:04:16.040
is the primary building block of react
00:04:17.799
apps so in react uh what we are doing is
00:04:20.919
just build components just build more
00:04:22.919
and more
00:04:25.120
components so this is the uh simple
00:04:27.720
example of U hello world component
00:04:29.759
component and uh this is the create
00:04:32.280
class API uh top level API of react uh
00:04:36.160
using which we can create a component uh
00:04:39.320
the uh every component must Implement a
00:04:41.960
render function so that that render
00:04:44.280
function specifies how your UI will look
00:04:46.919
and then there is a uh method react.
00:04:49.199
render using which we can render the uh
00:04:52.360
component hello component and we can
00:04:54.280
mount it on element like I I'm mounting
00:04:56.840
it here on document. body
00:05:01.000
so component is really a simple function
00:05:03.759
that's it it gets all the data that it
00:05:06.240
wants and it Returns the UI
00:05:08.840
specification that we want to render uh
00:05:12.680
ultimately now let's look at uh my
00:05:14.919
Twitter timeline so if we want to render
00:05:17.520
it using react what we'll do is we'll
00:05:19.360
just break things into different uh
00:05:21.479
Parts like uh the profile information
00:05:24.319
can go on its own component uh all the
00:05:27.160
tweets will go in their individual tweet
00:05:29.160
component
00:05:30.160
and uh we can break the other parts also
00:05:33.319
so for tweet counts if you want to
00:05:35.759
render the Tweet counts uh we send it
00:05:38.280
the uh data that it needs like tweets
00:05:40.560
count is something following count is
00:05:42.120
something uh we we send all the tweets
00:05:44.720
to individual tweets component so we are
00:05:48.160
sending all the data and that's why the
00:05:50.880
components are becoming reusable so uh a
00:05:53.759
component has everything that it needs
00:05:55.479
to render a particular piece of
00:05:57.880
UI and it's as it is just a small unit
00:06:01.360
it can be reused in other
00:06:04.039
places so like this I'm I'm composing
00:06:07.160
everything that I build earlier into a
00:06:08.880
big timeline so uh uh timeline is the
00:06:12.479
parent component and it it it is
00:06:14.800
composing of my tweet accounts tweets
00:06:16.840
and
00:06:18.440
Trends by building these small modular
00:06:21.720
components uh we get same advantage that
00:06:24.680
we are we get in our server side code
00:06:27.120
like in Ruby we always try to uh model
00:06:29.880
code in functions or classes which do a
00:06:32.080
single thing so similarly we get the
00:06:34.360
same Advantage but this time in our UI
00:06:38.000
code and this is the right separation of
00:06:41.000
concerns that react provides for uh for
00:06:43.479
our user interface so what we are
00:06:46.240
actually doing is we are doing uh we are
00:06:48.479
building a component library for our
00:06:50.759
domain and uh there is nothing new in
00:06:54.319
this concept like we we are already
00:06:56.039
doing this in our server side code but
00:06:58.840
uh react by default provides this so uh
00:07:02.199
as uh you have to build components in
00:07:04.280
react you are uh uh automatically doing
00:07:07.080
the automatically separating the
00:07:08.360
concerns uh by
00:07:11.879
default so let's look at uh our uh
00:07:15.120
component again uh as as the return uh
00:07:18.840
statement says it is just rendering the
00:07:20.840
HTML it is just uh rendering a d tag and
00:07:24.639
if you see closely we are writing HTML
00:07:28.039
in the JavaScript so it's bad right we
00:07:31.479
we we avoid this right we keep the HTML
00:07:34.680
separate from the JavaScript so HTML
00:07:36.919
templates are at separate place and
00:07:39.520
JavaScript that renders HTML is at
00:07:41.319
separate place so it's bad I'm I'm
00:07:44.039
confused why we are doing
00:07:46.000
it well this is not really HTML so what
00:07:49.319
we are doing here is we are uh using
00:07:51.520
something called a jsx uh which which
00:07:54.319
doesn't get eval so this doesn't get
00:07:56.080
evaluated into HTML string string but it
00:07:59.039
actually builds a component tree similar
00:08:01.000
to our Dom tree so this is not HTML it
00:08:05.080
is jsx and if we search what jsx is so
00:08:09.879
jsx is faster easier and um statically
00:08:13.440
type programming
00:08:14.800
language but jsx is bad it is not what
00:08:18.599
we want so jsx is so bad it even trolls
00:08:22.000
Google so if you search for jsx the
00:08:24.720
first search is uh something different
00:08:27.319
faster safer and uh whatever JavaScript
00:08:30.919
but we want the second search so jsx is
00:08:33.000
so bad that it even trolls
00:08:35.519
Google we want this so jsx is actually a
00:08:40.000
XML syntax extension for JavaScript uh
00:08:43.080
it allows us to write uh uh HTML tags so
00:08:47.080
that we can specify our our UI just like
00:08:50.320
Dom and it's not a separate language so
00:08:53.080
it is not something like coffeescript
00:08:55.279
which is built on top of JavaScript it's
00:08:57.720
just a a pre-processor so so before our
00:09:00.800
uh JavaScript gets deployed to
00:09:02.560
production we convert jsx code to normal
00:09:05.680
JavaScript and uh it it it's just acts
00:09:09.240
as a
00:09:10.640
pre-processor it is also optional so if
00:09:13.120
you don't want to use jsx you can skip
00:09:15.320
it and just go with the pure JavaScript
00:09:17.560
approach but I'm not sure uh like uh
00:09:21.399
many react developers might be going
00:09:23.160
with jsx approach they they will not go
00:09:25.519
with pure
00:09:28.360
JavaScript so it it jsx is allowing us
00:09:31.839
to U write H uh UI just like we do in
00:09:35.680
our normal HTML
00:09:38.480
stuff if you're still feeling a bit
00:09:41.279
annoyed about jsx uh it's it's actually
00:09:44.680
healthy for you uh you can uh like it it
00:09:48.160
can it can feel bad but you you can feel
00:09:51.720
guilty but it's actually good for you so
00:09:54.120
this is the quote from Eric OT and I got
00:09:57.000
inspired by this and I decided okay I
00:09:59.480
will also write something about jsx so
00:10:02.600
jsx is like
00:10:04.120
durian it it smells bad but it's
00:10:06.920
actually good uh you can tweet this if
00:10:08.920
you
00:10:10.000
want and
00:10:12.959
it's it's not just me our keynote
00:10:15.720
speakers also believe this so they are
00:10:17.600
happy eating the durian okay so I am
00:10:20.600
happy our keynote speakers are happy you
00:10:22.880
should also be happy about
00:10:24.920
jsx and if you're still annoyed just
00:10:27.480
give it five minutes uh I I know that uh
00:10:30.240
it is something that we are we we try to
00:10:32.519
avoid so this is a great blog post about
00:10:36.480
not reacting to uh anything uh without
00:10:39.440
thinking much so just give it five
00:10:41.639
minutes to jsx and um you'll feel good
00:10:44.480
you'll feel
00:10:46.720
easy okay so the next topic is no
00:10:49.440
templates react also doesn't have any
00:10:52.040
templating uh language associated with
00:10:53.880
it um so templating language the problem
00:10:57.440
with them is they're conceptually
00:10:58.920
similar what we want to do is uh we want
00:11:01.480
to uh have a loop which iterates over uh
00:11:04.760
our collection and does something we
00:11:07.120
want uh to have some conditional
00:11:09.000
statements like if if this then do this
00:11:11.120
else do this so these templating
00:11:13.920
languages uh they're conceptually
00:11:15.920
simpler uh similar but they have
00:11:17.839
different syntax so whenever I I'm
00:11:20.399
trying a new framework I I have to learn
00:11:23.000
uh if there is new syntax I have to
00:11:24.760
learn that and that's why react just U
00:11:27.959
goes the Javas script way so this is a
00:11:31.320
code by um jasim and he says that any um
00:11:35.440
any templating language is a slow
00:11:38.480
implementation bugden implementation of
00:11:40.600
a complete programming language so what
00:11:42.959
he's trying to say here is that you have
00:11:45.360
all those features present in the
00:11:46.920
programming language and in our case for
00:11:49.399
web uh that programming language is
00:11:52.279
Javascript so react uh instead of uh
00:11:55.160
using a temp instead of uh writing a new
00:11:57.320
templating language you just use
00:11:59.760
JavaScript so let's say I have a list of
00:12:02.160
tweets and I want to iterate over them
00:12:04.560
and render each tweet individually I
00:12:06.800
will just use the map function which is
00:12:09.040
provided by JavaScript so there is no
00:12:10.680
need to uh use a different templating
00:12:13.160
language uh react just uh leverages the
00:12:16.160
power of
00:12:18.959
JavaScript yeah so it is everything uh
00:12:21.920
finally uh is only JavaScript and this
00:12:25.240
means you can use your normal variables
00:12:27.360
control structures uh all the
00:12:29.639
programming abstractions that are
00:12:31.079
present in JavaScript and use uh and
00:12:34.240
write beautiful organized UI code view
00:12:39.279
code this is another problem in frontend
00:12:41.880
development like how you will manage the
00:12:43.800
state how you will manage uh when user
00:12:46.199
interacts with your Dom or your UI
00:12:49.120
something will change and then you have
00:12:50.839
to manage the state in your uh view
00:12:53.000
models or models uh you have to uh you
00:12:56.440
have to pass the data around and uh like
00:12:59.480
user should not feel that something is
00:13:01.199
gone wrong so managing State changes Dom
00:13:04.839
mutations it's
00:13:07.720
challenging Pete hunt who was the
00:13:10.040
original developer of U react he says
00:13:12.399
that it's data changing over time is
00:13:14.920
root of all
00:13:16.839
evil so react comes with something
00:13:19.839
called as props a shorter form of
00:13:22.360
properties so Props are
00:13:26.079
um like attributes of your HTML element
00:13:29.079
ments so let's say I want to um render a
00:13:32.240
tweet like this I have the Tweet content
00:13:34.320
and the uh author name
00:13:37.519
then props come from above
00:13:40.760
so the Tweet list component here is
00:13:43.560
sending the author information and the
00:13:45.560
content information so I'm just sending
00:13:48.000
tweet. author tweet. content and this
00:13:50.959
curly bres means that uh this code will
00:13:53.279
be evaluated uh as a JavaScript
00:13:55.279
expression so you just put any
00:13:57.480
JavaScript expression in those curly bra
00:13:59.519
and it will get evaluated and then it
00:14:02.240
comes uh comes below to the Tweet
00:14:04.399
component and we uh access those props
00:14:06.920
as this doprs this doprs do author and
00:14:09.839
this doprs do
00:14:11.800
content as you can see this is oneway
00:14:14.959
data flow so data is coming from parent
00:14:17.560
component to the child component it is
00:14:19.240
not like child component can pass data
00:14:22.519
uh yeah it can pass but right now just
00:14:25.720
uh uh let's uh remember that it's uh
00:14:28.759
data is coming from the
00:14:31.320
top props are also immutable so the
00:14:35.120
component that sends it owns the props
00:14:38.920
the child component doesn't own the
00:14:40.560
props so he uh the child component
00:14:42.279
cannot change those props and uh reuse
00:14:44.680
them he he has to depend on the uh
00:14:47.440
whatever data that is sent by parent
00:14:51.560
component react also allows uh to
00:14:54.560
validate props because uh sometimes what
00:14:57.160
happens is uh you're using some Library
00:14:59.800
and you want to make sure that okay uh
00:15:02.600
whatever data I'm passing the types are
00:15:04.880
correct so react also allows to do uh
00:15:07.680
this using prop types function uh where
00:15:10.079
you specify that okay my author should
00:15:12.279
be a string my content should be a
00:15:14.199
string uh my count should be a number so
00:15:17.880
in your component if you add this then
00:15:20.040
in development we get a warning that uh
00:15:22.279
if you are not following this U uh like
00:15:24.839
if if you not passing the uh data or if
00:15:27.360
you passing wrong type of data you get a
00:15:29.519
warning in development uh prop types
00:15:31.839
also allow to specify like uh is this
00:15:34.560
field required or is this uh uh is this
00:15:38.240
not required like you can pass it or
00:15:40.440
even you can skip it so it has a Syntax
00:15:42.720
for
00:15:44.839
that the second way of managing data in
00:15:47.920
react is using state so every component
00:15:51.600
can have its own
00:15:53.120
State and that state is internal so we
00:15:56.319
saw that uh a a component cannot change
00:15:59.319
its props which are passed by the uh
00:16:01.759
parent component but a component can
00:16:04.480
change its state because uh the state is
00:16:06.600
owned by that particular
00:16:09.800
component so to U uh get started with
00:16:13.440
State what we have is we have a initial
00:16:16.000
uh get initial State function uh so
00:16:18.440
whenever every component renders this is
00:16:20.279
the first function that gets evaluated
00:16:22.480
and you can set the initial State just
00:16:24.880
like our um initialized method that we
00:16:27.160
use in our normal uh Ruby code
00:16:29.440
this is the initialized method for react
00:16:31.920
um and then uh in the render instead of
00:16:34.399
props we are using this do state. props
00:16:37.360
so we have the uh access to that state
00:16:40.600
as this do state do
00:16:44.560
something react tries to avoid State as
00:16:47.279
much as possible and the issue with
00:16:49.959
state is uh Changing State keeping it at
00:16:52.639
different places and managing it is hard
00:16:55.160
so what react says is that you should
00:16:57.160
avoid States as much as possible
00:16:58.920
possible so state is uh like most of the
00:17:02.959
times state is present in the uh the
00:17:05.559
topmost parent component and then you
00:17:07.919
pass props below so the child components
00:17:10.880
they are stateless and Stat uh stateless
00:17:13.959
components are preferred in react so if
00:17:17.760
you can render a component using only
00:17:19.720
props that's better don't go for State
00:17:22.400
just use that props keep uh keep State
00:17:26.240
at a minimum place like don't uh don't
00:17:29.039
use state if it is not
00:17:31.200
required it's actually a sort of anti
00:17:33.760
pattern to use too many stateful
00:17:35.919
components in
00:17:38.200
react but we know right state will be
00:17:41.120
there we can't eliminate it completely
00:17:43.160
like in my tweets example if I'm pulling
00:17:45.760
new tweets from the server there has to
00:17:48.039
be a component which will pull that data
00:17:50.160
from the server and will pass it to the
00:17:51.880
child components so how we will respond
00:17:54.679
to U State
00:17:57.679
changes now now react provides some
00:18:00.080
event uh some life cycle hooks so
00:18:03.120
whenever component gets uh mounted we
00:18:05.880
get this hook component did Mount and we
00:18:08.360
can execute our code to fetch the data
00:18:10.559
from uh server so here I have written a
00:18:13.600
simple load post function which loads
00:18:15.320
the post and then when the uh posts are
00:18:18.760
fetched from the server I change the
00:18:21.400
state so whatever the initial state was
00:18:24.240
it gets updated using this set State
00:18:26.400
function and then I pass a JavaScript
00:18:28.520
object like whatever the uh fetch posts
00:18:30.919
were I just assign it to
00:18:33.720
posts now um if we consider the web 1.0
00:18:37.880
era uh whenever something used to change
00:18:40.840
the simplest solution was just refresh
00:18:42.840
the page you get the new data so U that
00:18:46.280
that worked for a while but as we are
00:18:48.320
writing more and more interactive apps
00:18:50.159
it's not possible we can't refresh the
00:18:51.799
whole page we we want to render we want
00:18:54.120
to uh change specific parts of the
00:18:57.039
page and Rea does that by re-rendering
00:19:00.520
that particular component so whenever a
00:19:03.200
state of a particular component changes
00:19:05.679
react just reenders
00:19:08.440
it so whenever the state changes here
00:19:12.280
render function will get called and post
00:19:14.919
will be rendered again so that
00:19:16.760
particular component will get rendered
00:19:19.600
again and it's not just that particular
00:19:22.480
component because it can be a parent
00:19:24.440
component so it can have child
00:19:26.280
components below it so it will reender
00:19:28.400
the whole component
00:19:30.840
tree now you must be thinking why we are
00:19:33.400
doing this re-rendering will it not make
00:19:35.720
my app slow why we are rendering every
00:19:38.360
time a simple uh simple thing in state
00:19:41.200
changes so it turns out that they have
00:19:44.240
thought about it and virtual Dom comes
00:19:47.320
in the picture so it's not actually slow
00:19:49.840
because of virtual Dom so uh in react we
00:19:54.400
never deal with the actual Dom we are
00:19:56.360
always uh always working with the fake
00:19:59.400
Dom which react keeps track of a track
00:20:01.360
for
00:20:02.400
us so we saw the um uh uh return value
00:20:06.799
for this hello component what it
00:20:08.840
actually returns is something like this
00:20:10.559
react. create element so it is not
00:20:13.480
returning actual HTML as I said earlier
00:20:15.919
it is returning a description of that D
00:20:18.760
tag it is returning a u
00:20:22.559
specification so what happens is
00:20:25.440
whenever State changes what react does
00:20:27.360
is it creates a virtual Dom for new
00:20:29.360
state it it diffs it with the current uh
00:20:32.440
whatever the Val whatever the
00:20:33.799
description that is present in the
00:20:35.000
memory it diffs with it so that it finds
00:20:37.840
minimal changes so if if I'm rendering
00:20:40.840
uh 10 tweets and nine of them are not
00:20:42.679
changed then it will only find the one
00:20:45.400
tweet that needs to be rendered so it it
00:20:47.559
uh finds only the minimal set of
00:20:50.559
changes the other thing react does is it
00:20:53.000
does batch updates so uh all the um Dom
00:20:56.480
changes that needs to be done they are
00:20:58.880
done in a single
00:21:00.640
call and that's why it is really fast if
00:21:04.200
you think of it nothing is new here we
00:21:06.799
already know that Dom changes are
00:21:08.520
expensive we should limit uh uh the
00:21:10.760
number of changes that we are doing to
00:21:12.200
Dom we already know that batch updates
00:21:14.559
are fast and we already know that uh if
00:21:17.679
we uh if we try to do something in our
00:21:20.360
JavaScript code it will make our uh
00:21:22.440
interactive apps faster but react sort
00:21:25.760
of gives it for free so even without you
00:21:28.760
knowing it it is doing it for
00:21:31.720
you so that was first part of the talk I
00:21:34.919
talked about uh few Concepts a few ideas
00:21:37.840
that react uses now let's see uhu how
00:21:41.080
react can be integrated with rails so
00:21:43.480
there is a good news for everyone
00:21:45.000
because it is far easier to integrate
00:21:47.200
react in rails rather than setting up a
00:21:50.760
project with u JavaScript tools like
00:21:53.520
gulp grun uh watchify and
00:21:56.360
everything so there is a offical gem
00:21:59.279
react rails uh and this gem allows to
00:22:01.880
integrate uh uh rails with react very
00:22:05.600
easily it provides a generator for
00:22:08.080
installing react and then uh it creates
00:22:11.400
like it adds um react JavaScript react
00:22:14.360
unup to JavaScript and it creates two
00:22:16.960
these directories like uh all of your
00:22:18.679
components should be in this app assets
00:22:21.080
component directory and then a single
00:22:23.360
file for U managing the list of
00:22:26.080
components in that directory it also
00:22:28.640
takes care of converting your jsx code
00:22:30.880
to Pure JavaScript code so you just have
00:22:33.360
to write js. jsx files and uh the gem
00:22:37.080
will take care of converting it before
00:22:39.200
assets are actually
00:22:41.159
pre-compiled so this is a simple Erb
00:22:43.320
snippet I'm uh iterating over the posts
00:22:46.159
and rendering author and content and
00:22:48.640
this is how it gets rendered now if you
00:22:50.960
want to use react for this then we will
00:22:53.799
uh remove the code for rendering TR and
00:22:56.360
th and we will replace it with called to
00:22:58.799
react
00:23:00.080
component react component is a helper
00:23:02.559
method which is provided by the gem uh
00:23:05.000
the first argument is what is the name
00:23:07.159
of your component so here I want to
00:23:08.880
render post component then I can pass
00:23:11.400
whatever props I want to pass so uh as
00:23:13.960
we are using rails it will take care of
00:23:16.360
um converting this active record object
00:23:18.200
to Json and pass it to um
00:23:20.640
react by default it renders everything
00:23:23.520
into a d tag so we can specify some HTML
00:23:26.360
options like I want to uh render is in a
00:23:28.880
TR tag because it is part of a
00:23:31.840
table and this is the output of that
00:23:34.039
code so uh we have data react class and
00:23:37.279
we have data react props uh all the Json
00:23:40.440
data of our props is
00:23:43.360
there now next step is we write actually
00:23:46.480
the component in uh jsx so we write
00:23:49.320
post. js. jsx and it gets that this.
00:23:52.840
props dopost we get the data because we
00:23:54.960
passed it
00:23:56.279
earlier we passed it as a post
00:23:59.360
and then we render it uh normally like
00:24:01.679
this doprs do post. author and
00:24:04.080
content and we get the um same output
00:24:07.120
that we had earlier but this time using
00:24:09.000
react and this is how it actually looks
00:24:12.000
if you uh check it in console that data
00:24:15.080
react class and data react property is
00:24:18.000
there uh this is a this was a simple
00:24:20.360
example um if we want to poll new post
00:24:24.000
uh for a after a certain amount of time
00:24:27.000
instead of sending the post data
00:24:28.640
directly we can send a URL so here I'm
00:24:30.840
sending which URL uh the client uh react
00:24:34.000
can Poll for new
00:24:36.240
posts and then uh we can set a timeout
00:24:39.200
that every 5 Seconds fetch load uh fetch
00:24:41.600
new post and render everything uh I will
00:24:44.640
go a little fast because I'm running out
00:24:46.760
of time so what it does is it uh pulls
00:24:51.480
the post and renders the whole table
00:24:54.200
again uh this gem also syncs with asset
00:24:56.880
pre asset pipeline so
00:24:59.120
uh it it works beautifully with asset P
00:25:01.520
pipeline without coming into the way uh
00:25:04.080
you can specify uh certain variants like
00:25:06.880
if you want to use development version
00:25:08.520
or production version I think it also
00:25:10.760
allows to uh specify your own version uh
00:25:14.159
your own version of
00:25:16.320
reactjs uh this gem also allows uh
00:25:19.159
server side rendering so you can pass
00:25:21.559
option for pre-rendering pre-render true
00:25:24.399
and it will evaluate the code on server
00:25:26.679
side and then send it back
00:25:29.200
so there are some uh issues with server
00:25:32.000
side rendering because you don't have
00:25:34.240
access to the document the document.
00:25:36.360
body body so we can't use any uh
00:25:39.360
JavaScript library like jQuery we don't
00:25:41.399
have access to that when the code is uh
00:25:44.000
getting evaluated on server side also if
00:25:46.919
you're using any dependencies like
00:25:48.600
underscorejs or something then you have
00:25:50.799
to specify all the dependencies in your
00:25:53.080
components. JS file because uh react
00:25:55.760
rails uh uses this component.js JS file
00:25:59.159
to load everything and then your
00:26:01.679
components must be in the global name
00:26:04.120
space uh it also shifts with a generator
00:26:06.880
so similar to how we generate models
00:26:09.120
controllers we can generate a a
00:26:11.120
component we just specify uh that I want
00:26:13.880
content to be a string count to be an
00:26:15.840
integer and it generates this uh tweet.
00:26:18.600
js. jsx file uh we get prop prop types
00:26:22.159
for free and we get uh like scaffolding
00:26:25.880
it is similar to
00:26:27.240
scaffolding
00:26:29.279
now this is a new hot thing that uh came
00:26:31.960
out recently react native it is a
00:26:34.399
framework for uh building native apps
00:26:36.559
using react based on react so you write
00:26:38.919
similar uh components similar to this
00:26:41.240
but this time they will be specific for
00:26:43.240
iOS or Android uh Android is not there
00:26:45.799
but they're talking about um uh
00:26:48.919
releasing it soon so the react
00:26:51.480
philosophy is uh learn once and write
00:26:54.399
two apps so we are not going to write a
00:26:57.120
single app which will work for IOS and
00:26:59.200
Android instead you learn react once and
00:27:01.640
then you can write a separate IOS app
00:27:03.799
and separate Android
00:27:05.919
app now if you think of a learning curve
00:27:08.520
whenever we are looking at a new
00:27:09.840
technology we have to also check how
00:27:12.159
much uh how much time I have can I can I
00:27:14.840
uh is this really worth if uh I invest
00:27:17.880
my time in it and fortunately for react
00:27:21.880
uh just knowing JavaScript is enough
00:27:24.200
because everything is Javascript there
00:27:25.679
is no templating language there is no uh
00:27:28.799
extra thing that you have to know and
00:27:31.559
JavaScript plus jsx but as I said jsx is
00:27:35.320
ultimately JavaScript so if you know
00:27:37.159
just JavaScript it is enough other thing
00:27:40.240
is uh as it doesn't care about your
00:27:42.399
existing stack you can sneak into
00:27:44.519
existing projects let's try react for
00:27:46.799
some feature doesn't work out then it's
00:27:49.120
okay we can go for something else so try
00:27:52.080
react let me know your experience how
00:27:53.960
you're uh using react or if you're
00:27:55.799
already using react let me know that's
00:27:58.640
it uh we also have some U react video
00:28:01.799
series which you can check um uh we have
00:28:04.840
a u uh to-do app series the second link
00:28:08.880
and the first link is uh for getting
00:28:10.960
started with react thank
00:28:26.120
you