This New React Hook Breaks All The Rules And I Love It

This New React Hook Breaks All The Rules And I Love It

Web Dev Simplified

1 год назад

179,204 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Michael Vik
Michael Vik - 14.09.2023 08:20

I feel like this should have been called "useUse" hook

Ответить
Mindaugas Ažubalis
Mindaugas Ažubalis - 08.09.2023 21:19

Awesomeness 🎉🎉🎉

Ответить
JohnnySalami
JohnnySalami - 25.08.2023 04:51

I don't really see the value of "use" when it just replaces async/await??

Ответить
KuBa
KuBa - 16.08.2023 01:16

They should name it useUse

Ответить
Nathan Budd
Nathan Budd - 14.07.2023 23:41

I didn't quite follow the Context bit at the end... does this mean you could use the "use" hook in the context to fetch data, then share it across multiple components?

Ответить
Shantanu Sharma
Shantanu Sharma - 11.06.2023 11:21

Support you sir 🎉

Ответить
raduneo
raduneo - 21.04.2023 18:54

Svelte is where it's gonna at... but this hook does look cool nonetheless.

Ответить
Koder Kev
Koder Kev - 19.04.2023 18:48

"This New React Hook Breaks All The Rules", sums up why many devs dread front-end development. JS allows (and often encourages) so much hacky code that it becomes a nightmare to maintain. Solutions to bugs/problems often involves hunting down yet another library or version update. I'm for constant-learning but this is madness.

Ответить
Michal Mocny
Michal Mocny - 15.04.2023 15:45

Doesn't use+fetch.then cause infinite network requests? It's like the useEffect without deps footgun. You have to ensure the promise it stable across renders, and can use cache() for that, before handing it use()

Ответить
ytadi
ytadi - 12.04.2023 20:55

Weird how we still end up class based component just for ErrorBoundary

Ответить
Sodoff Baldrick
Sodoff Baldrick - 07.04.2023 04:07

I'll stick with react-query, but will keep an eye on this little hooky

Ответить
Gaurav poudel
Gaurav poudel - 02.04.2023 17:46

Ur awesome man

Ответить
Mohan Kumar
Mohan Kumar - 28.03.2023 13:27

I have created the exact use case for custom hook for fetching, they could have created a concept of utils rather than hooks.

Ответить
Dvir Hanum
Dvir Hanum - 28.03.2023 01:10

Why? Isn't it possible to put useContext in a condition right now?

Ответить
Oli
Oli - 24.03.2023 03:20

I wish I was as good as you, great content you got a new sub

Ответить
tailsonrails
tailsonrails - 23.03.2023 14:11

If I use this, this is not the only thing confusing about JS anymore.

Ответить
Pimpaka Stewart
Pimpaka Stewart - 21.03.2023 12:32

loved !!!!

Ответить
Noah
Noah - 19.03.2023 19:58

This is not exactly the same though. The Error Boundary catches *any* error, not just a network error.

Ответить
Eugene Pranoto
Eugene Pranoto - 16.03.2023 10:28

May i ask how the getderivedstatefromerror trigger if we are using react redux query?

Ответить
Axel J. Solares
Axel J. Solares - 16.03.2023 01:33

This was mind blowing!!

Ответить
MaxArt
MaxArt - 14.03.2023 18:01

My question is: HOW?
The reason why hooks can't be used inside `if` statements is that they're tracked in sequence. A branch condition (or an iteration) breaks the sequence.
This is important because hooks aren't named or tied to the component instance in any way, so React needs to keep a stack in order to perform the correct action.
But if you can put `use` inside an conditional it means that's not actually tracked. So what's the secret?

Ответить
Dominik Sosnowski
Dominik Sosnowski - 11.03.2023 14:35

Did you do already a video on useSignal? Is it also in experimental?

Ответить
Jack Garlick
Jack Garlick - 11.03.2023 05:55

You’re acting like it’s simpler but you’ve added twice as much boilerplate

Ответить
Alex Black
Alex Black - 11.03.2023 00:56

Great video. Thanks for taking the time to make this. Very helpful.

Ответить
Dominick
Dominick - 10.03.2023 19:05

... So, they're basically moving the boilerplate code up to the parents and making everything more "magical" (aka confusing)

Ответить
Technology && Gaming With Mehdi
Technology && Gaming With Mehdi - 09.03.2023 20:54

I think, its time to say good bye to React.

Ответить
Christian Lauridsen
Christian Lauridsen - 09.03.2023 18:24

hooks are in general shite... like really shite... i love vue so much, its incredible.. however at work I have to use react, I don't get it, vue is so over powered compared to react..

Ответить
Abby Chau
Abby Chau - 08.03.2023 11:13

could you reduce the size of your avatar in the latter videos?

Ответить
Joel Brighton
Joel Brighton - 08.03.2023 01:12

Maybe I'm missing something here but with the original technique the 'loading' and 'error' handling were all contained in the original component. Now, with Suspense and ErrorBoundary we have pulled this logic out of the original component into the host component. So, every time we use the revised component we have to repeat this logic or, more likely, wrap it inside another component which contains just the ErrorBoundary, Suspense and revised component. Is this really an improvement? Am I just not seeing the light?

Ответить
GuerillaRadio
GuerillaRadio - 08.03.2023 00:02

Not sure I’m a fan of this, I’d have to have a play with some real use cases (excuse the pun), but initially it looks nasty wrapping components in another two components that don’t actually render anything.

Ответить
Gregg Bolinger
Gregg Bolinger - 07.03.2023 20:31

Neat, but it's just parts of react-query's useQuery. And if use() doesn't at least do what useQuery already does, why would I use use()? use use use use use.

Ответить
bloody_albatross
bloody_albatross - 06.03.2023 19:05

Let me get this straight, this now performs a fetch every time the component is rendered!?

Generally I don't like functional components sans for the most simple cases. I find class components much more easy to understand, much easier to see what is happening. I think calling them functional components is a misnomer. They are anything but adhering to functional principles with their magical global state. If you're component gets a little bit more complex such a huge function gets really confusing quickly.

Ответить
Veritas
Veritas - 06.03.2023 19:01

React in itself is a boilerplate for corporate abstraction

Ответить
RemX405
RemX405 - 06.03.2023 06:16

Or.... you just extract your default fetch routine/Error handling/Loading component stuff inside a function/custom hook, you code it once, and you reuse it everywhere, and your error handling state is still local to your component. The error boundary thing seems like a nice fallback, but not a proper way to handle errors for specific requests. All these indirections kinda goes against the principles of a declarative react component IMO.

Ответить
owenn04
owenn04 - 06.03.2023 04:54

I like everything but the error handling part. So much easier to just catch the error then wrap ur components in some weird class

Ответить
Help Me Get 100,000 subs by tomorrow!
Help Me Get 100,000 subs by tomorrow! - 06.03.2023 02:29

Using HOC for Suspense and ErrorBoundy sounds useful.

Ответить
Daniel Král
Daniel Král - 06.03.2023 00:50

So its not only more rows. Its also multiple files for a single fetch. In this case I dont see it as a win. Its again overengineering. It would be better if the use hook worked without the suspense and boundary.... this is kinda meh. I mean suspense & boundary does have a place but its not as straight forward. And over using it just kinda makes your code more unreadable since you cant see everything at glance.

Ответить
NullPointerBug
NullPointerBug - 05.03.2023 20:33

So we just move error handling and loading state to somewhere else. Not confusing at all.

Ответить
Eshironde
Eshironde - 05.03.2023 11:56

It looks nice, but it feels like React is just reinventing JavaScript that you have to write with React syntax :P

Ответить
Anvar Saidov
Anvar Saidov - 04.03.2023 19:19

Thank you for suspense and errorBoundary.

Ответить
Nil
Nil - 04.03.2023 14:38

I have no idea how it works behind the scenes but being able to run hooks conditionally? Hell yeah. I hated having to create container components that conditionally rendered just to be able to conditionally run a hook. Or doing things like passing `skip: true` to the hook that fetches gql data.

Ответить
Glory NT
Glory NT - 04.03.2023 10:59

its should be 'use' to 'useFull'

Ответить
Execute
Execute - 04.03.2023 03:00

useSwr is better than this

Ответить
חי זוהר
חי זוהר - 04.03.2023 01:01

the useEffect had the url in the dependency array so it won't keep fetching the data on every render, does use do the same?

Ответить
Ramiro Rojo
Ramiro Rojo - 03.03.2023 19:14

React needs something like React.errorBoundary((props, error) => <div>{error ? error : props.children}</div>), so we can catch errors using function components

Ответить
Manuel Ernst
Manuel Ernst - 03.03.2023 13:03

so the use hook is basically react-query with less features.

Ответить
SEO Book Pro - Technical SEO and Custom Software
SEO Book Pro - Technical SEO and Custom Software - 03.03.2023 05:52

What about pass cors when fetch external data
Promise/await not help if the external server don’t have cors enabled
This is for internal works

Ответить
Rami GB
Rami GB - 03.03.2023 04:45

Embrace yourselves for components full of nested and conditional use hooks. Good luck PR reviewers :D .. jokes aside this looks amazing, thanks for the video man.

Ответить