No video

React Components with GENERICS? - Advanced TypeScript

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

Matt Pocock

Matt Pocock

Күн бұрын

Пікірлер: 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 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 172 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 37 МЛН
小丑把天使丢游泳池里#short #angel #clown
00:15
Super Beauty team
Рет қаралды 48 МЛН
나랑 아빠가 아이스크림 먹을 때
00:15
진영민yeongmin
Рет қаралды 4,5 МЛН
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 134 М.
Enums considered harmful
9:23
Matt Pocock
Рет қаралды 203 М.
Learn TypeScript Generics In 13 Minutes
12:52
Web Dev Simplified
Рет қаралды 257 М.
This is why learning typescript generics is important
13:19
Web Dev Cody
Рет қаралды 25 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 585 М.
Never Forget React forwardRef Again
9:33
Coding in Public
Рет қаралды 17 М.
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН