Unleashing the Power of Duck-Typing in React: Crafting a Generic Application by David Villamarin
Aug 6, 2025
For React developers, the typical practice when creating React applications involves generating components, pages, and routes for various features required by the application. This process can become laborious, dedicating extensive hours to fine-tuning the implementation details. However, what if you are uncertain about the components your page application will encompass? One might assume that such an application cannot be developed. Fear not!
We all have heard "If it walks like a duck and it quacks like a duck, then it must be a duck". It is called "duck typing" a TypeScript’s core principle: type checking focuses on the shape that values have. This powerful concept is used to determine whether an object can be used for a particular purpose, which means that if an object behaves like a certain type, then it can be treated as that type. The idea is to describe duck typing, using TS examples, checking why duck typing is important, and we'll check together when and when not to use it.
How can we apply this concept to a react application?
Duck typing offers a powerful and flexible way of working with objects, eliminating concerns about their specific internal content. Once we've established duck-typing functions for all our application components, such as inputs, checkboxes, buttons, lists, modals, and custom components, we can channel them through a component switchyard. The outcome of this process is then rendered to the UI as a page.
But why should React developers specifically embrace duck typing in TypeScript?
Duck typing provides a way to achieve type safety by allowing us to define and validate the expected shapes of our components. This ensures that only compatible components are used together, reducing the likelihood of runtime errors and enhancing the robustness of our applications. With clearly defined types, refactoring becomes a smooth process, and the compiler assists in catching potential issues early in the development phase, contributing to a more maintainable codebase.
In this talk, you will learn about duck typing in TypeScript, focusing on a React application. Following this pattern makes it possible to build generic applications that serve an unlimited number of pages.
Table of contents
1. What and Why Duck-typing?
- General description
- Advantages / Disadvantages
- Examples
2. Overview of a generic React application written in TS
- Routing
Show More Show Less View Video Transcript
0:03
cool
0:05
cool
0:05
cool uh uh welcome everybody uh who's joining
0:09
uh uh welcome everybody uh who's joining
0:09
uh uh welcome everybody uh who's joining um this is my my very first uh
0:12
um this is my my very first uh
0:12
um this is my my very first uh conference talk so I'm really excited to
0:15
conference talk so I'm really excited to
0:15
conference talk so I'm really excited to to be here uh to be part of this of this
0:18
to be here uh to be part of this of this
0:18
to be here uh to be part of this of this conference um today um we are going to
0:22
conference um today um we are going to
0:22
conference um today um we are going to talk about typescript about pract and of
0:26
talk about typescript about pract and of
0:26
talk about typescript about pract and of course the the the main goal for for
0:28
course the the the main goal for for
0:28
course the the the main goal for for this session is is going to be H
0:30
this session is is going to be H
0:30
this session is is going to be H crafting a a generic
0:33
crafting a a generic
0:33
crafting a a generic application um so yeah let's jump to to
0:36
application um so yeah let's jump to to
0:36
application um so yeah let's jump to to see how how how you can do
0:40
see how how how you can do
0:40
see how how how you can do this uh first of all uh who am I as
0:43
this uh first of all uh who am I as
0:43
this uh first of all uh who am I as Simon said um I'm I'm I'm equadorian uh
0:48
Simon said um I'm I'm I'm equadorian uh
0:48
Simon said um I'm I'm I'm equadorian uh I'm a I consider myself a developer uh
0:51
I'm a I consider myself a developer uh
0:51
I'm a I consider myself a developer uh by day and also a chess player by by
0:54
by day and also a chess player by by
0:55
by day and also a chess player by by night um I work at UH at the stack
0:58
night um I work at UH at the stack
0:58
night um I work at UH at the stack Builders uh we are consultancy focus on
1:01
Builders uh we are consultancy focus on
1:01
Builders uh we are consultancy focus on functional programming and functional
1:03
functional programming and functional
1:03
functional programming and functional languages but uh we also do cool coolest
1:07
languages but uh we also do cool coolest
1:07
languages but uh we also do cool coolest stuff uh with typescript uh Python and
1:11
stuff uh with typescript uh Python and
1:11
stuff uh with typescript uh Python and other framework other languages and also
1:14
other framework other languages and also
1:14
other framework other languages and also different Frameworks um I also consider
1:18
different Frameworks um I also consider
1:18
different Frameworks um I also consider myself an open source contributor uh
1:21
myself an open source contributor uh
1:21
myself an open source contributor uh recently I I created um a semantic
1:24
recently I I created um a semantic
1:24
recently I I created um a semantic release plugin for uploading a packages
1:28
release plugin for uploading a packages
1:28
release plugin for uploading a packages to to hackage that is is basically the
1:31
to to hackage that is is basically the
1:31
to to hackage that is is basically the the package manager for for hcll so so
1:35
the package manager for for hcll so so
1:35
the package manager for for hcll so so yeah um really excited to to to be here
1:38
yeah um really excited to to to be here
1:38
yeah um really excited to to to be here today and first of all I I want to to to
1:42
today and first of all I I want to to to
1:42
today and first of all I I want to to to start with a with a disclaimer um uh I
1:46
start with a with a disclaimer um uh I
1:46
start with a with a disclaimer um uh I really like react um this is this is
1:49
really like react um this is this is
1:49
really like react um this is this is like a a use case
1:51
like a a use case
1:51
like a a use case um um sorry like a scenario
1:56
um um sorry like a scenario
1:56
um um sorry like a scenario um a case Studio basically so um this is
2:00
um a case Studio basically so um this is
2:00
um a case Studio basically so um this is probably not the best solution but this
2:02
probably not the best solution but this
2:02
probably not the best solution but this is a one of the
2:05
is a one of the
2:05
is a one of the different I'm sure that the there there
2:08
different I'm sure that the there there
2:08
different I'm sure that the there there could be different different ways of
2:11
could be different different ways of
2:11
could be different different ways of doing uh generic functions with with re
2:14
doing uh generic functions with with re
2:14
doing uh generic functions with with re EXO this is just uh one one of them um
2:18
EXO this is just uh one one of them um
2:18
EXO this is just uh one one of them um so yeah what what do we have for for
2:20
so yeah what what do we have for for
2:20
so yeah what what do we have for for today first of all we we are going to to
2:24
today first of all we we are going to to
2:24
today first of all we we are going to to to start talking uh about dog
2:27
to start talking uh about dog
2:27
to start talking uh about dog typing um what and why using do typing
2:32
typing um what and why using do typing
2:32
typing um what and why using do typing and then we are going to see the the the
2:36
and then we are going to see the the the
2:36
and then we are going to see the the the main Concepts the the the main things
2:39
main Concepts the the the main things
2:39
main Concepts the the the main things that that we need for uh for creating
2:42
that that we need for uh for creating
2:42
that that we need for uh for creating this the generic application of course
2:44
this the generic application of course
2:44
this the generic application of course we need uh components I created a a good
2:48
we need uh components I created a a good
2:48
we need uh components I created a a good um uh a cool component called switch art
2:51
um uh a cool component called switch art
2:51
um uh a cool component called switch art you're going to see a wife um why why I
2:56
you're going to see a wife um why why I
2:56
you're going to see a wife um why why I call it switch and later on we we will
2:59
call it switch and later on we we will
2:59
call it switch and later on we we will will see how how to wrad a a generic
3:03
will see how how to wrad a a generic
3:03
will see how how to wrad a a generic application and of course um just minor
3:07
application and of course um just minor
3:07
application and of course um just minor and simple easy to to understand uh
3:10
and simple easy to to understand uh
3:10
and simple easy to to understand uh examples um so yeah this is this is
3:13
examples um so yeah this is this is
3:13
examples um so yeah this is this is going to be a a simplified version of
3:16
going to be a a simplified version of
3:16
going to be a a simplified version of something that that I will in my in my
3:18
something that that I will in my in my
3:18
something that that I will in my in my current project um yeah so let's start
3:22
current project um yeah so let's start
3:22
current project um yeah so let's start first of all do typing um so what is
3:28
first of all do typing um so what is
3:28
first of all do typing um so what is doct typing um Simon s was was was
3:31
doct typing um Simon s was was was
3:31
doct typing um Simon s was was was saying something um something about it
3:34
saying something um something about it
3:34
saying something um something about it um but yeah duct typing is um is coming
3:38
um but yeah duct typing is um is coming
3:38
um but yeah duct typing is um is coming from something that is that is called
3:41
from something that is that is called
3:41
from something that is that is called the dock test and you can see here um
3:44
the dock test and you can see here um
3:44
the dock test and you can see here um this is the the dock test so it it says
3:47
this is the the dock test so it it says
3:47
this is the the dock test so it it says basically if it if it looks like a duck
3:51
basically if it if it looks like a duck
3:51
basically if it if it looks like a duck swims like a duck and quacks like a duck
3:54
swims like a duck and quacks like a duck
3:54
swims like a duck and quacks like a duck then it probably is a du right so this
3:57
then it probably is a du right so this
3:57
then it probably is a du right so this test implies that a a person can Iden
4:01
test implies that a a person can Iden
4:01
test implies that a a person can Iden identify an unknown
4:04
identify an unknown
4:04
identify an unknown subject uh an unknown in this case
4:06
subject uh an unknown in this case
4:06
subject uh an unknown in this case Animal by observing the the the the
4:10
Animal by observing the the the the
4:10
Animal by observing the the the the different aspect the different
4:12
different aspect the different
4:12
different aspect the different characteristics of this um um of this
4:17
characteristics of this um um of this
4:17
characteristics of this um um of this subject right so this is just pure
4:20
subject right so this is just pure
4:20
subject right so this is just pure logical inference and um the idea here
4:24
logical inference and um the idea here
4:24
logical inference and um the idea here is checking the behavior the different
4:26
is checking the behavior the different
4:26
is checking the behavior the different properties and based on this INF
4:30
properties and based on this INF
4:30
properties and based on this INF uh uh logic we can uh say basically what
4:35
uh uh logic we can uh say basically what
4:35
uh uh logic we can uh say basically what could be it to to to to to whatever that
4:38
could be it to to to to to whatever that
4:39
could be it to to to to to whatever that we are trying to identify so this is
4:42
we are trying to identify so this is
4:43
we are trying to identify so this is applied to to to programming uh so
4:45
applied to to to programming uh so
4:45
applied to to to programming uh so basically we if we have two objects uh
4:48
basically we if we have two objects uh
4:48
basically we if we have two objects uh with the same properties with the same
4:52
with the same properties with the same
4:52
with the same properties with the same uh could be methods could be functions
4:56
uh could be methods could be functions
4:56
uh could be methods could be functions uh we can we can say basically that this
4:59
uh we can we can say basically that this
4:59
uh we can we can say basically that this uh
5:00
uh
5:00
uh these two um objects are are of the same
5:04
these two um objects are are of the same
5:04
these two um objects are are of the same type so here we are checking this this
5:07
type so here we are checking this this
5:07
type so here we are checking this this these different type Concepts um and why
5:11
these different type Concepts um and why
5:11
these different type Concepts um and why why why using this uh this doc typing we
5:14
why why using this uh this doc typing we
5:14
why why using this uh this doc typing we are going to see different concepts uh
5:16
are going to see different concepts uh
5:16
are going to see different concepts uh next but I I wanted to to to to say this
5:20
next but I I wanted to to to to say this
5:20
next but I I wanted to to to to say this this here because it's it can help us in
5:24
this here because it's it can help us in
5:24
this here because it's it can help us in in different ways um first of all is
5:27
in different ways um first of all is
5:27
in different ways um first of all is flexibility and simplicity
5:29
flexibility and simplicity
5:29
flexibility and simplicity um that's that's one um basically the or
5:33
um that's that's one um basically the or
5:34
um that's that's one um basically the or code could could be simpler and with and
5:39
code could could be simpler and with and
5:39
code could could be simpler and with and avoid this cou coupling code um in the
5:43
avoid this cou coupling code um in the
5:44
avoid this cou coupling code um in the same in the same way uh and when when
5:47
same in the same way uh and when when
5:47
same in the same way uh and when when you do this these kind of things you are
5:50
you do this these kind of things you are
5:50
you do this these kind of things you are encouraging better code uh with
5:53
encouraging better code uh with
5:53
encouraging better code uh with different aspects of
5:56
different aspects of
5:56
different aspects of reusability modularity and of course
5:58
reusability modularity and of course
5:58
reusability modularity and of course maintainability so these are like the
6:01
maintainability so these are like the
6:01
maintainability so these are like the pros of uh using du typing so we are
6:05
pros of uh using du typing so we are
6:05
pros of uh using du typing so we are going to see um how you can Implement so
6:09
going to see um how you can Implement so
6:09
going to see um how you can Implement so first let's start with a with an
6:11
first let's start with a with an
6:11
first let's start with a with an important um uh typescript con with
6:15
important um uh typescript con with
6:15
important um uh typescript con with different uh typescript Concepts the the
6:17
different uh typescript Concepts the the
6:17
different uh typescript Concepts the the first one is type narrowing so basically
6:20
first one is type narrowing so basically
6:20
first one is type narrowing so basically this is a this is a very simple um this
6:24
this is a this is a very simple um this
6:24
this is a this is a very simple um this a very simple uh process for asserting a
6:28
a very simple uh process for asserting a
6:28
a very simple uh process for asserting a type um in a particular in a particular
6:32
type um in a particular in a particular
6:32
type um in a particular in a particular part of our of our of our data flow so
6:36
part of our of our of our data flow so
6:36
part of our of our of our data flow so in this case we have this this pading
6:38
in this case we have this this pading
6:38
in this case we have this this pading that could be a number and and a string
6:41
that could be a number and and a string
6:41
that could be a number and and a string um so in this specific
6:45
um so in this specific
6:45
um so in this specific um conditional that we have here we are
6:48
um conditional that we have here we are
6:48
um conditional that we have here we are defining we are basically narrowing the
6:51
defining we are basically narrowing the
6:52
defining we are basically narrowing the type to to um to the case when this
6:56
type to to um to the case when this
6:56
type to to um to the case when this padding is just a number so inside of
6:59
padding is just a number so inside of
6:59
padding is just a number so inside of this line five um we we can we can use
7:05
this line five um we we can we can use
7:05
this line five um we we can we can use uh pading just as a number uh so we can
7:09
uh pading just as a number uh so we can
7:09
uh pading just as a number uh so we can run different functions uh different
7:12
run different functions uh different
7:12
run different functions uh different number uh functions such as to fix to
7:15
number uh functions such as to fix to
7:15
number uh functions such as to fix to exponential for example and of course
7:18
exponential for example and of course
7:18
exponential for example and of course once we are out of the scope of this
7:21
once we are out of the scope of this
7:21
once we are out of the scope of this conditional we can keep uh treating the
7:25
conditional we can keep uh treating the
7:25
conditional we can keep uh treating the the pading as a as or other type right
7:29
the pading as a as or other type right
7:29
the pading as a as or other type right um so it is going to be an string at
7:31
um so it is going to be an string at
7:31
um so it is going to be an string at this level and it's going to be a number
7:35
this level and it's going to be a number
7:35
this level and it's going to be a number here um and of course uh so we can we
7:39
here um and of course uh so we can we
7:39
here um and of course uh so we can we can do uh an an execute functions that
7:43
can do uh an an execute functions that
7:43
can do uh an an execute functions that are related to to Strings so for example
7:46
are related to to Strings so for example
7:46
are related to to Strings so for example conat uh contains uh subring we can
7:50
conat uh contains uh subring we can
7:50
conat uh contains uh subring we can uppercase or lowercase this this padding
7:53
uppercase or lowercase this this padding
7:53
uppercase or lowercase this this padding here but not at this level so basically
7:56
here but not at this level so basically
7:56
here but not at this level so basically this just this is just a technique to
7:58
this just this is just a technique to
7:58
this just this is just a technique to allow us that allow us to take a type
8:01
allow us that allow us to take a type
8:01
allow us that allow us to take a type that is too broad and refine it to a
8:04
that is too broad and refine it to a
8:04
that is too broad and refine it to a more specific one and this is uh this
8:07
more specific one and this is uh this
8:08
more specific one and this is uh this process is really important because um
8:10
process is really important because um
8:10
process is really important because um for creating a generic application we
8:13
for creating a generic application we
8:13
for creating a generic application we are going to use uh something called
8:17
are going to use uh something called
8:17
are going to use uh something called type predicate functions so this is just
8:21
type predicate functions so this is just
8:21
type predicate functions so this is just a function that return volum value and
8:25
a function that return volum value and
8:25
a function that return volum value and and have a a type uh syntax return so as
8:29
and have a a type uh syntax return so as
8:29
and have a a type uh syntax return so as you can see here we can handle uh um
8:34
you can see here we can handle uh um
8:34
you can see here we can handle uh um anything basically X could be anything
8:37
anything basically X could be anything
8:37
anything basically X could be anything here um we don't know what is X but
8:41
here um we don't know what is X but
8:41
here um we don't know what is X but after we use this uh type predicate
8:44
after we use this uh type predicate
8:44
after we use this uh type predicate function we are we're making sure that
8:48
function we are we're making sure that
8:48
function we are we're making sure that um um whatever is in X at that specific
8:51
um um whatever is in X at that specific
8:51
um um whatever is in X at that specific moment is going to be a string so we are
8:54
moment is going to be a string so we are
8:54
moment is going to be a string so we are doing this uh by checking um if
9:00
doing this uh by checking um if
9:00
doing this uh by checking um if if an object in this case this x has an
9:03
if an object in this case this x has an
9:03
if an object in this case this x has an specific property or set of properties
9:05
specific property or set of properties
9:05
specific property or set of properties for now since string um is like just an
9:11
for now since string um is like just an
9:11
for now since string um is like just an string uh we can we we don't have any
9:14
string uh we can we we don't have any
9:14
string uh we can we we don't have any other properties but uh we can achieve
9:17
other properties but uh we can achieve
9:17
other properties but uh we can achieve the the same result basically using in
9:20
the the same result basically using in
9:20
the the same result basically using in type off or could be also use uh we can
9:24
type off or could be also use uh we can
9:24
type off or could be also use uh we can use also instance of that are um
9:27
use also instance of that are um
9:27
use also instance of that are um keywords of typescript
9:30
keywords of typescript
9:30
keywords of typescript yeah
9:31
yeah
9:31
yeah so um we have narrowing we have type
9:34
so um we have narrowing we have type
9:34
so um we have narrowing we have type predicates and then we have typ guards
9:38
predicates and then we have typ guards
9:38
predicates and then we have typ guards so what is a userdefined typ guard
9:41
so what is a userdefined typ guard
9:41
so what is a userdefined typ guard basically this is a function whose
9:43
basically this is a function whose
9:44
basically this is a function whose return uh whose return type is a type
9:46
return uh whose return type is a type
9:46
return uh whose return type is a type predicate right so we are composing
9:49
predicate right so we are composing
9:49
predicate right so we are composing these previous Concepts um basically
9:52
these previous Concepts um basically
9:52
these previous Concepts um basically that allow you to create custom logic to
9:55
that allow you to create custom logic to
9:55
that allow you to create custom logic to determine whether a value is of an
9:57
determine whether a value is of an
9:57
determine whether a value is of an specific type so in this uh little
10:00
specific type so in this uh little
10:00
specific type so in this uh little example we can we can have a pet a
10:04
example we can we can have a pet a
10:04
example we can we can have a pet a little pet right a small pet um that
10:06
little pet right a small pet um that
10:06
little pet right a small pet um that could be a fish or could or could be a
10:09
could be a fish or could or could be a
10:09
could be a fish or could or could be a bird so basically the the idea here is
10:14
bird so basically the the idea here is
10:14
bird so basically the the idea here is if we assume that pet is a fish of
10:18
if we assume that pet is a fish of
10:18
if we assume that pet is a fish of course we are going to have a property
10:20
course we are going to have a property
10:20
course we are going to have a property or a method or a function basically that
10:25
or a method or a function basically that
10:25
or a method or a function basically that um called Swim that is going to be
10:28
um called Swim that is going to be
10:28
um called Swim that is going to be different uh then undefine it right so
10:32
different uh then undefine it right so
10:32
different uh then undefine it right so this explains it better so basically we
10:35
this explains it better so basically we
10:35
this explains it better so basically we can have a pet uh we are getting an
10:39
can have a pet uh we are getting an
10:39
can have a pet uh we are getting an small pet we don't know what it is could
10:41
small pet we don't know what it is could
10:41
small pet we don't know what it is could be a fish could be a bird but uh once we
10:44
be a fish could be a bird but uh once we
10:44
be a fish could be a bird but uh once we use this tyare basically we are making
10:48
use this tyare basically we are making
10:48
use this tyare basically we are making sure that in the scope of this
10:50
sure that in the scope of this
10:50
sure that in the scope of this conditional the first part of the E
10:53
conditional the first part of the E
10:53
conditional the first part of the E statement basically we can handle a fish
10:56
statement basically we can handle a fish
10:56
statement basically we can handle a fish here right and same as in the type
11:00
here right and same as in the type
11:00
here right and same as in the type narrowing example we we just have two
11:03
narrowing example we we just have two
11:03
narrowing example we we just have two options so the other option must be a
11:06
options so the other option must be a
11:06
options so the other option must be a right so we can assume that uh pet can
11:10
right so we can assume that uh pet can
11:10
right so we can assume that uh pet can can can we can execute this fly uh
11:15
can can we can execute this fly uh
11:15
can can we can execute this fly uh function here so basically uh typ
11:20
function here so basically uh typ
11:20
function here so basically uh typ guards enable uh type safety for code
11:25
guards enable uh type safety for code
11:25
guards enable uh type safety for code and better compile time error error
11:27
and better compile time error error
11:27
and better compile time error error checking um so yeah this improves our
11:30
checking um so yeah this improves our
11:30
checking um so yeah this improves our our development development experience
11:33
our development development experience
11:33
our development development experience and let's jump to react right now so
11:38
and let's jump to react right now so
11:38
and let's jump to react right now so yeah we are going to create uh just so a
11:42
yeah we are going to create uh just so a
11:42
yeah we are going to create uh just so a couple of of components and then we are
11:46
couple of of components and then we are
11:46
couple of of components and then we are concatenate all of them in on the
11:48
concatenate all of them in on the
11:48
concatenate all of them in on the switcher so what do we need for the for
11:51
switcher so what do we need for the for
11:52
switcher so what do we need for the for the for the components first of all an
11:54
the for the components first of all an
11:54
the for the components first of all an interface just um to define the
11:57
interface just um to define the
11:57
interface just um to define the different properties that every
11:59
different properties that every
11:59
different properties that every component is going to have so in this
12:02
component is going to have so in this
12:02
component is going to have so in this example we have uh five components so
12:05
example we have uh five components so
12:05
example we have uh five components so for example here is the input or the
12:08
for example here is the input or the
12:08
for example here is the input or the text area that could have an ID could
12:11
text area that could have an ID could
12:11
text area that could have an ID could have a text could have a value um for
12:14
have a text could have a value um for
12:14
have a text could have a value um for example here the same thing but we have
12:16
example here the same thing but we have
12:16
example here the same thing but we have a checkbox so this is the the the Model
12:20
a checkbox so this is the the the Model
12:20
a checkbox so this is the the the Model H for for for the checkbox um we can do
12:23
H for for for the checkbox um we can do
12:23
H for for for the checkbox um we can do the same thing for a more complex um
12:27
the same thing for a more complex um
12:27
the same thing for a more complex um component so for example this button
12:29
component so for example this button
12:29
component so for example this button that could handle different actions
12:31
that could handle different actions
12:31
that could handle different actions right and of course to uh we have
12:33
right and of course to uh we have
12:33
right and of course to uh we have different different H variants on the um
12:38
different different H variants on the um
12:38
different different H variants on the um when working with common UI libraries so
12:41
when working with common UI libraries so
12:42
when working with common UI libraries so so yeah this could be another option and
12:43
so yeah this could be another option and
12:43
so yeah this could be another option and also we can have icon for example yeah
12:47
also we can have icon for example yeah
12:47
also we can have icon for example yeah so this is just the last the last
12:50
so this is just the last the last
12:50
so this is just the last the last example of a of an of a model of a of a
12:54
example of a of an of a model of a of a
12:54
example of a of an of a model of a of a of a component that could be an
12:55
of a component that could be an
12:55
of a component that could be an accordion so basically we can have
12:59
accordion so basically we can have
12:59
accordion so basically we can have anything inside an accordion so in this
13:01
anything inside an accordion so in this
13:01
anything inside an accordion so in this case we are having this property that
13:04
case we are having this property that
13:04
case we are having this property that can handle whatever that is inside
13:06
can handle whatever that is inside
13:06
can handle whatever that is inside basically component model is
13:09
basically component model is
13:10
basically component model is um uh type unknown right so what are we
13:15
um uh type unknown right so what are we
13:15
um uh type unknown right so what are we going to do next we are going to Define
13:17
going to do next we are going to Define
13:17
going to do next we are going to Define our type Parts yeah so for every
13:21
our type Parts yeah so for every
13:21
our type Parts yeah so for every component in or application we um are
13:26
component in or application we um are
13:26
component in or application we um are going to Define this typ card function
13:29
going to Define this typ card function
13:29
going to Define this typ card function um where pce of all CMP could be
13:33
um where pce of all CMP could be
13:33
um where pce of all CMP could be whatever could be this unknown that we
13:36
whatever could be this unknown that we
13:36
whatever could be this unknown that we have here uh so we are not sure if it is
13:38
have here uh so we are not sure if it is
13:38
have here uh so we are not sure if it is or if it isn't but uh we can be sure
13:42
or if it isn't but uh we can be sure
13:42
or if it isn't but uh we can be sure that if this uh is um this this
13:48
that if this uh is um this this
13:48
that if this uh is um this this component this CMP sorry has like um all
13:54
component this CMP sorry has like um all
13:54
component this CMP sorry has like um all these um text input model properties the
13:58
these um text input model properties the
13:58
these um text input model properties the one that we Define on the models for
14:01
one that we Define on the models for
14:01
one that we Define on the models for every component so basically we can
14:03
every component so basically we can
14:03
every component so basically we can return a type uh predicate that is
14:07
return a type uh predicate that is
14:07
return a type uh predicate that is saying that this is going to be an input
14:10
saying that this is going to be an input
14:10
saying that this is going to be an input yeah so we can keep this this this this
14:15
yeah so we can keep this this this this
14:15
yeah so we can keep this this this this this idea of uh checking the properties
14:19
this idea of uh checking the properties
14:19
this idea of uh checking the properties of this object um using using guards and
14:24
of this object um using using guards and
14:24
of this object um using using guards and uh with this uh type predicate basic
14:28
uh with this uh type predicate basic
14:28
uh with this uh type predicate basic with this predicate basically we can we
14:30
with this predicate basically we can we
14:30
with this predicate basically we can we can be sure that um for example this
14:34
can be sure that um for example this
14:34
can be sure that um for example this thing here when we are using this
14:37
thing here when we are using this
14:37
thing here when we are using this function it's going to be a checkbox
14:39
function it's going to be a checkbox
14:39
function it's going to be a checkbox it's going to be a button it's going to
14:41
it's going to be a button it's going to
14:41
it's going to be a button it's going to be an accordion and so on of course of
14:43
be an accordion and so on of course of
14:43
be an accordion and so on of course of course this could keep extending to to
14:47
course this could keep extending to to
14:47
course this could keep extending to to uh as many components as as you
14:49
uh as many components as as you
14:49
uh as many components as as you want so uh where everything comes
14:54
want so uh where everything comes
14:54
want so uh where everything comes together in this switchyard uh I call it
14:58
together in this switchyard uh I call it
14:58
together in this switchyard uh I call it this this component a switch art because
15:02
this this component a switch art because
15:02
this this component a switch art because um basically you can have uh whatever
15:07
um basically you can have uh whatever
15:07
um basically you can have uh whatever the the type of comp here could be
15:10
the the type of comp here could be
15:11
the the type of comp here could be whatever could be an string could be
15:13
whatever could be an string could be
15:13
whatever could be an string could be undefined could be an all could be a a
15:16
undefined could be an all could be a a
15:17
undefined could be an all could be a a type of text input model could be a
15:19
type of text input model could be a
15:19
type of text input model could be a checkbox model could be whatever but in
15:22
checkbox model could be whatever but in
15:23
checkbox model could be whatever but in inside of this component we are making
15:25
inside of this component we are making
15:25
inside of this component we are making sure uh to render um the the the the the
15:30
sure uh to render um the the the the the
15:30
sure uh to render um the the the the the proper component that we want right so
15:33
proper component that we want right so
15:33
proper component that we want right so this is uh the the logic here is H
15:37
this is uh the the logic here is H
15:37
this is uh the the logic here is H checking the properties of this comp if
15:41
checking the properties of this comp if
15:41
checking the properties of this comp if it is true that this is a text input
15:44
it is true that this is a text input
15:44
it is true that this is a text input model of course we are going to reender
15:46
model of course we are going to reender
15:46
model of course we are going to reender an input text and this logic is the same
15:50
an input text and this logic is the same
15:50
an input text and this logic is the same for all all of this so yeah we are we
15:55
for all all of this so yeah we are we
15:55
for all all of this so yeah we are we can do checkbox we can do Bon we can do
15:58
can do checkbox we can do Bon we can do
15:58
can do checkbox we can do Bon we can do accordion with um some extra props uh to
16:03
accordion with um some extra props uh to
16:03
accordion with um some extra props uh to these to these components um just to to
16:06
these to these components um just to to
16:06
these to these components um just to to to to keep uh all the all the flow
16:09
to to keep uh all the all the flow
16:09
to to keep uh all the all the flow together and of course we can have a
16:13
together and of course we can have a
16:13
together and of course we can have a this is a this is a common pattern on
16:14
this is a this is a common pattern on
16:14
this is a this is a common pattern on react like having a default case when
16:18
react like having a default case when
16:18
react like having a default case when you are doing some conditional rendering
16:20
you are doing some conditional rendering
16:20
you are doing some conditional rendering that is basically all of these um and
16:23
that is basically all of these um and
16:23
that is basically all of these um and you can have a missing component and
16:26
you can have a missing component and
16:26
you can have a missing component and that that is going to say like you hav
16:28
that that is going to say like you hav
16:28
that that is going to say like you hav an implemented this this this this new
16:30
an implemented this this this this new
16:30
an implemented this this this this new component this come with these
16:33
component this come with these
16:33
component this come with these different
16:35
different
16:35
different properties um so yeah uh of course you
16:39
properties um so yeah uh of course you
16:39
properties um so yeah uh of course you have to um create your components um
16:44
have to um create your components um
16:44
have to um create your components um just as you will for any other
16:46
just as you will for any other
16:46
just as you will for any other application so for example we have input
16:49
application so for example we have input
16:49
application so for example we have input text here um of course we we know that
16:52
text here um of course we we know that
16:52
text here um of course we we know that one of the one of the prop of the props
16:56
one of the one of the prop of the props
16:56
one of the one of the prop of the props uh for for this component is going to be
16:58
uh for for this component is going to be
16:58
uh for for this component is going to be this comp
16:59
this comp
16:59
this comp that we are making sure through do dog
17:02
that we are making sure through do dog
17:02
that we are making sure through do dog typing and that this is a text input
17:05
typing and that this is a text input
17:05
typing and that this is a text input model so we can use uh the different
17:08
model so we can use uh the different
17:08
model so we can use uh the different values inside of this component so for
17:10
values inside of this component so for
17:10
values inside of this component so for example in this case uh comp. value
17:13
example in this case uh comp. value
17:14
example in this case uh comp. value could be uh default value for uh this
17:17
could be uh default value for uh this
17:18
could be uh default value for uh this this specific input that as you can see
17:20
this specific input that as you can see
17:20
this specific input that as you can see this just uh is a is a pretty basic
17:24
this just uh is a is a pretty basic
17:24
this just uh is a is a pretty basic input text with uh with some label right
17:29
input text with uh with some label right
17:29
input text with uh with some label right and of course we are managing right now
17:31
and of course we are managing right now
17:31
and of course we are managing right now the the internal state with a with an
17:33
the the internal state with a with an
17:33
the the internal state with a with an use State could be is also a ref but the
17:37
use State could be is also a ref but the
17:37
use State could be is also a ref but the important thing here is that comp will
17:40
important thing here is that comp will
17:40
important thing here is that comp will only contain the model properties that
17:43
only contain the model properties that
17:43
only contain the model properties that we are uh expecting um
17:48
we are uh expecting um
17:48
we are uh expecting um inside in basically inside this this
17:51
inside in basically inside this this
17:51
inside in basically inside this this condition that I I just showed you in
17:53
condition that I I just showed you in
17:53
condition that I I just showed you in this uh in this uh in this slide right
17:57
this uh in this uh in this slide right
17:57
this uh in this uh in this slide right so here comp is of the text input model
18:01
so here comp is of the text input model
18:01
so here comp is of the text input model here is a checkbox model here is a
18:04
here is a checkbox model here is a
18:04
here is a checkbox model here is a botton model and of course here well of
18:07
botton model and of course here well of
18:07
botton model and of course here well of course comp is an accordion model so um
18:11
course comp is an accordion model so um
18:11
course comp is an accordion model so um this is the way of when right now we are
18:15
this is the way of when right now we are
18:15
this is the way of when right now we are at the point that we created our
18:16
at the point that we created our
18:16
at the point that we created our components we Define our components we
18:19
components we Define our components we
18:19
components we Define our components we Define our switch art so what is missing
18:21
Define our switch art so what is missing
18:21
Define our switch art so what is missing for having a
18:24
for having a
18:24
for having a um uh a generic application uh of course
18:27
um uh a generic application uh of course
18:27
um uh a generic application uh of course routing right and we are going to see
18:30
routing right and we are going to see
18:30
routing right and we are going to see just now the the routing so first of all
18:34
just now the the routing so first of all
18:34
just now the the routing so first of all of course we will need a a route uh this
18:37
of course we will need a a route uh this
18:37
of course we will need a a route uh this is like a a pre basic road that is using
18:42
is like a a pre basic road that is using
18:42
is like a a pre basic road that is using an an ID as a as a
18:45
an an ID as a as a
18:45
an an ID as a as a parm um so basically uh you can you can
18:50
parm um so basically uh you can you can
18:50
parm um so basically uh you can you can you can handle as many IDs as as you
18:53
you can handle as many IDs as as you
18:53
you can handle as many IDs as as you want I I call it apps because if you are
18:57
want I I call it apps because if you are
18:57
want I I call it apps because if you are creating a generic application
18:59
creating a generic application
18:59
creating a generic application um this is for me this is no longer an
19:03
um this is for me this is no longer an
19:03
um this is for me this is no longer an application it's more like a platform so
19:06
application it's more like a platform so
19:06
application it's more like a platform so what whatever that you are going to have
19:08
what whatever that you are going to have
19:08
what whatever that you are going to have inside is going to be like a a little
19:11
inside is going to be like a a little
19:11
inside is going to be like a a little application right so what is the
19:15
application right so what is the
19:15
application right so what is the important part here uh that in our road
19:18
important part here uh that in our road
19:18
important part here uh that in our road we can Define this this response this
19:21
we can Define this this response this
19:21
we can Define this this response this rest um that is basically an array of
19:24
rest um that is basically an array of
19:24
rest um that is basically an array of objects with all of the of the of the
19:27
objects with all of the of the of the
19:27
objects with all of the of the of the pages that we want to handle and that we
19:31
pages that we want to handle and that we
19:31
pages that we want to handle and that we want that or generic application handles
19:33
want that or generic application handles
19:34
want that or generic application handles right um in this in this sense of course
19:38
right um in this in this sense of course
19:38
right um in this in this sense of course these these Pages or applications as I
19:41
these these Pages or applications as I
19:41
these these Pages or applications as I like to to call them um can come from
19:45
like to to call them um can come from
19:45
like to to call them um can come from from an HTTP request could come from a
19:49
from an HTTP request could come from a
19:49
from an HTTP request could come from a from a web socket but the important part
19:52
from a web socket but the important part
19:52
from a web socket but the important part here is like passing this through this
19:55
here is like passing this through this
19:55
here is like passing this through this component called adlet yeah and then
19:59
component called adlet yeah and then
19:59
component called adlet yeah and then what what is inside the the the adlet um
20:03
what what is inside the the the adlet um
20:03
what what is inside the the the adlet um we have an application that is defined
20:06
we have an application that is defined
20:06
we have an application that is defined and this application um have like an
20:10
and this application um have like an
20:10
and this application um have like an skeleton and inside the skeleton we have
20:12
skeleton and inside the skeleton we have
20:13
skeleton and inside the skeleton we have the components right so what is
20:16
the components right so what is
20:16
the components right so what is the basically components is an array of
20:19
the basically components is an array of
20:19
the basically components is an array of all the different components that you
20:21
all the different components that you
20:21
all the different components that you want right
20:23
want right
20:23
want right and this uh generic idea um go
20:30
and this uh generic idea um go
20:30
and this uh generic idea um go uh mapping when when you map this this
20:33
uh mapping when when you map this this
20:33
uh mapping when when you map this this array this components array basically
20:36
array this components array basically
20:36
array this components array basically you are saying well you have this switch
20:39
you are saying well you have this switch
20:39
you are saying well you have this switch chart please check what to render
20:43
chart please check what to render
20:43
chart please check what to render basically right so um depending on what
20:49
basically right so um depending on what
20:49
basically right so um depending on what uh Properties or on what
20:53
uh Properties or on what
20:53
uh Properties or on what um objects uh I I I have here at the in
20:57
um objects uh I I I have here at the in
20:57
um objects uh I I I have here at the in the in the component array uh of course
21:00
the in the component array uh of course
21:00
the in the component array uh of course I'm going to render different things uh
21:03
I'm going to render different things uh
21:03
I'm going to render different things uh on the application so let's see an app
21:08
on the application so let's see an app
21:08
on the application so let's see an app object basically so as a as I as I was
21:12
object basically so as a as I as I was
21:12
object basically so as a as I as I was saying before uh this is like an uh this
21:17
saying before uh this is like an uh this
21:17
saying before uh this is like an uh this has like an app skeleton property and
21:20
has like an app skeleton property and
21:20
has like an app skeleton property and inside the app skeleton we have the
21:23
inside the app skeleton we have the
21:23
inside the app skeleton we have the components it's opening here this array
21:25
components it's opening here this array
21:25
components it's opening here this array and it's closing here so this is a this
21:27
and it's closing here so this is a this
21:27
and it's closing here so this is a this is just a continuation um so what do we
21:31
is just a continuation um so what do we
21:31
is just a continuation um so what do we have here we have um I don't know we
21:34
have here we have um I don't know we
21:34
have here we have um I don't know we have a type that is a text that could
21:37
have a type that is a text that could
21:37
have a type that is a text that could could be just an an static text uh what
21:40
could be just an an static text uh what
21:40
could be just an an static text uh what do we have here in the next uh in the
21:43
do we have here in the next uh in the
21:43
do we have here in the next uh in the next item of of the components array we
21:47
next item of of the components array we
21:47
next item of of the components array we have a type
21:48
have a type
21:48
have a type input um with a text name for example
21:52
input um with a text name for example
21:52
input um with a text name for example and then um at the end just pretty basic
21:57
and then um at the end just pretty basic
21:57
and then um at the end just pretty basic application we have a a submit button
22:00
application we have a a submit button
22:00
application we have a a submit button right with with no options for now so
22:03
right with with no options for now so
22:03
right with with no options for now so he's not doing anything but with with
22:07
he's not doing anything but with with
22:07
he's not doing anything but with with another property that is a variant so I
22:10
another property that is a variant so I
22:10
another property that is a variant so I don't know for the ones who have used
22:12
don't know for the ones who have used
22:12
don't know for the ones who have used mui or chakra we have different variant
22:15
mui or chakra we have different variant
22:15
mui or chakra we have different variant like outline it contain it could be text
22:18
like outline it contain it could be text
22:18
like outline it contain it could be text so the idea is that you can Define the
22:22
so the idea is that you can Define the
22:22
so the idea is that you can Define the the different buttons that you that you
22:24
the different buttons that you that you
22:24
the different buttons that you that you want so what is the output of all of
22:27
want so what is the output of all of
22:27
want so what is the output of all of this uh what what is the final result is
22:30
this uh what what is the final result is
22:30
this uh what what is the final result is that you can have a homepage uh with
22:32
that you can have a homepage uh with
22:32
that you can have a homepage uh with your different applications and for
22:35
your different applications and for
22:35
your different applications and for example this one is is the object that
22:38
example this one is is the object that
22:38
example this one is is the object that we just just so um so this is the this
22:43
we just just so um so this is the this
22:43
we just just so um so this is the this is the static text that is saying just
22:45
is the static text that is saying just
22:45
is the static text that is saying just please write your name of the input
22:47
please write your name of the input
22:47
please write your name of the input below we have an input with a name and
22:50
below we have an input with a name and
22:50
below we have an input with a name and we have
22:52
we have
22:52
we have a an outlined uh button right with the
22:57
a an outlined uh button right with the
22:57
a an outlined uh button right with the with the text submit
22:59
with the text submit
22:59
with the text submit and this is just pretty basic pretty
23:01
and this is just pretty basic pretty
23:01
and this is just pretty basic pretty simple but of course you can have uh a
23:05
simple but of course you can have uh a
23:05
simple but of course you can have uh a better uh form right with more things
23:09
better uh form right with more things
23:09
better uh form right with more things just a full name email you can handle a
23:13
just a full name email you can handle a
23:13
just a full name email you can handle a phone ER I I mean number inputs uh could
23:17
phone ER I I mean number inputs uh could
23:17
phone ER I I mean number inputs uh could be a big text area for the comments also
23:20
be a big text area for the comments also
23:20
be a big text area for the comments also here we have check boxes for example we
23:23
here we have check boxes for example we
23:23
here we have check boxes for example we for accepting the terms of policy and we
23:26
for accepting the terms of policy and we
23:26
for accepting the terms of policy and we have another another another
23:29
have another another another
23:29
have another another another um type another variant of another Buton
23:32
um type another variant of another Buton
23:32
um type another variant of another Buton variant basically here um with the with
23:35
variant basically here um with the with
23:35
variant basically here um with the with the same text um so yeah basically this
23:39
the same text um so yeah basically this
23:40
the same text um so yeah basically this is like the way of you
23:42
is like the way of you
23:42
is like the way of you can for for you to create a a generic
23:46
can for for you to create a a generic
23:46
can for for you to create a a generic application um this is a a valid pattern
23:50
application um this is a a valid pattern
23:50
application um this is a a valid pattern on on the on the react uh world so I
23:55
on on the on the react uh world so I
23:55
on on the on the react uh world so I just wanted to to to say the the takeway
23:58
just wanted to to to say the the takeway
23:58
just wanted to to to say the the takeway ways for for for for this for this for
24:01
ways for for for for this for this for
24:01
ways for for for for this for this for this little talk so first of all Doc
24:04
this little talk so first of all Doc
24:04
this little talk so first of all Doc typing can can be applied to to a react
24:06
typing can can be applied to to a react
24:06
typing can can be applied to to a react application right using narrowing using
24:09
application right using narrowing using
24:09
application right using narrowing using these type predicates and of course
24:11
these type predicates and of course
24:12
these type predicates and of course using the the type parts so yeah that's
24:15
using the the type parts so yeah that's
24:15
using the the type parts so yeah that's one point the other the next point is of
24:18
one point the other the next point is of
24:18
one point the other the next point is of course re is is good enough for for
24:20
course re is is good enough for for
24:20
course re is is good enough for for creating generic applications and and
24:24
creating generic applications and and
24:24
creating generic applications and and yeah I invite all all all of the the the
24:27
yeah I invite all all all of the the the
24:27
yeah I invite all all all of the the the the react uh experts the the
24:30
the react uh experts the the
24:30
the react uh experts the the react Community to change your your
24:34
react Community to change your your
24:34
react Community to change your your mindset the way that you develop react
24:38
mindset the way that you develop react
24:38
mindset the way that you develop react um creating a project like this try to
24:41
um creating a project like this try to
24:41
um creating a project like this try to make things generic and of course this
24:44
make things generic and of course this
24:44
make things generic and of course this is not all the all the work of course we
24:46
is not all the all the work of course we
24:46
is not all the all the work of course we we need backend support and and more
24:49
we need backend support and and more
24:49
we need backend support and and more things but yeah you can you can you can
24:53
things but yeah you can you can you can
24:53
things but yeah you can you can you can achieve a a generic application uh using
24:57
achieve a a generic application uh using
24:57
achieve a a generic application uh using uh using just react and and typescript
25:00
uh using just react and and typescript
25:00
uh using just react and and typescript yes um yeah that's all for for for for
25:04
yes um yeah that's all for for for for
25:04
yes um yeah that's all for for for for my talk thank you for for for the
25:06
my talk thank you for for for the
25:06
my talk thank you for for for the attention uh if you have uh any any any
25:09
attention uh if you have uh any any any
25:09
attention uh if you have uh any any any questions I'm happy to to to to answer
25:14
questions I'm happy to to to to answer
25:14
questions I'm happy to to to to answer and you can see here the this this this
25:17
and you can see here the this this this
25:17
and you can see here the this this this code um well you can you can find the
25:21
code um well you can you can find the
25:21
code um well you can you can find the the code with a Rea with a real example
25:24
the code with a Rea with a real example
25:24
the code with a Rea with a real example with different applications
25:27
with different applications
25:27
with different applications of the that that I created here just a
25:30
of the that that I created here just a
25:30
of the that that I created here just a repo um I don't want to get the credit
25:33
repo um I don't want to get the credit
25:34
repo um I don't want to get the credit for for for these slides uh this was
25:36
for for for these slides uh this was
25:36
for for for these slides uh this was created using slides go and also some of
25:40
created using slides go and also some of
25:40
created using slides go and also some of the images that that you just saw are
25:42
the images that that you just saw are
25:42
the images that that you just saw are from preck so yeah this is um this is it
25:47
from preck so yeah this is um this is it
25:47
from preck so yeah this is um this is it thank you thank you very much
25:49
thank you thank you very much
25:49
thank you thank you very much [Music]


