No video

React Components with GENERICS? - Advanced TypeScript

  Рет қаралды 27,621

Matt Pocock

Matt Pocock

Күн бұрын

Become a TypeScript Wizard with Matt's upcoming TypeScript Course:
www.mattpocock...
Follow Matt on Twitter
/ mattpocockuk

Пікірлер: 21
@nick97000
@nick97000 2 жыл бұрын
Also found that adding a comma after the generic arg allows you to still use arrow functions
@PrevalentAA
@PrevalentAA 2 жыл бұрын
Thanks!
@thgosii
@thgosii Жыл бұрын
nice
@alexandercherniavenko7363
@alexandercherniavenko7363 2 жыл бұрын
You can use generic with an arrow function in jsx. To do so use next: (with comma at the end)
@ilonachan
@ilonachan Жыл бұрын
because that way the typescript parser can tell the difference between a JSX tag and a generics list, right?
@PrevalentAA
@PrevalentAA 2 жыл бұрын
Thank you Matt. These bite sized videos on more specific and localised topics are great. Keep them coming!
@workflowinmind
@workflowinmind Жыл бұрын
Very nice. This is now accepted too btw (0:37)
@mariolazzari
@mariolazzari Жыл бұрын
Brillant! Really helpful for typing mu custom data table component. Great job!
@williamcory4689
@williamcory4689 Жыл бұрын
You can also just use () => to make it not ambigious in tsx files
@amirbagjani5800
@amirbagjani5800 2 жыл бұрын
Thanks for sharing your knowledge 👍🏾 You can use this
@farahrayis5928
@farahrayis5928 2 жыл бұрын
It's pretty cool indeed. Thanks.
@user-lm5ju8nc2t
@user-lm5ju8nc2t 2 жыл бұрын
I find your videos very cool! But it would be even cooler if you took a small js lib and taught generics by adding types to it, on real word example)
@neuodev
@neuodev Жыл бұрын
You are amazing!
@sergeymild
@sergeymild 2 жыл бұрын
how will it looks like if i need wrap my component in forwardRef?
@NareshKumarPanneerSelvam
@NareshKumarPanneerSelvam 4 ай бұрын
how can we use generics for forwardRef type
@mattpocockuk
@mattpocockuk 4 ай бұрын
www.totaltypescript.com/forwardref-with-generic-components
@archmad
@archmad 2 жыл бұрын
You dont need to turn it into function, const is fine but use extends instead
@jeffnikelson5824
@jeffnikelson5824 2 жыл бұрын
but be carefull since it's easy to lose type-safety with this approach
@mattpocockuk
@mattpocockuk 2 жыл бұрын
Could you clarify what you mean?
@jeffnikelson5824
@jeffnikelson5824 2 жыл бұрын
@@mattpocockuk I mean that the more complex you go on a generic component the more you get into trouble and find yourself writing high complexity logic and edge-cases that only apply to one specific type that you have to cover since its generic. Its fine for simple components but in a more advanced case it is better to write more code but therefore be rewarded with clear type-safety.
@mattpocockuk
@mattpocockuk 2 жыл бұрын
@@jeffnikelson5824 It depends, you can constrain the generic that gets passed in so the part about 'high complexity logic' doesn't ring true for me if you have good constraints.
Master Generic Slots in TypeScript - Advanced TypeScript
2:00
Matt Pocock
Рет қаралды 17 М.
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 134 М.
SPONGEBOB POWER-UPS IN BRAWL STARS!!!
08:35
Brawl Stars
Рет қаралды 22 МЛН
Kids' Guide to Fire Safety: Essential Lessons #shorts
00:34
Fabiosa Animated
Рет қаралды 17 МЛН
Чёрная ДЫРА 🕳️ | WICSUR #shorts
00:49
Бискас
Рет қаралды 6 МЛН
what will you choose? #tiktok
00:14
Анастасия Тарасова
Рет қаралды 7 МЛН
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 172 М.
as const: the most underrated TypeScript feature
5:38
Matt Pocock
Рет қаралды 117 М.
Learn TypeScript Generics In 13 Minutes
12:52
Web Dev Simplified
Рет қаралды 257 М.
Enums considered harmful
9:23
Matt Pocock
Рет қаралды 203 М.
This TS naming convention is weird
4:01
Matt Pocock
Рет қаралды 116 М.
Everyone's talking about gql.tada
5:06
Matt Pocock
Рет қаралды 43 М.
Learn React Generic Components In 6 Minutes
6:47
Web Dev Simplified
Рет қаралды 54 М.
SPONGEBOB POWER-UPS IN BRAWL STARS!!!
08:35
Brawl Stars
Рет қаралды 22 МЛН