Rebuild React Hooks yourself for Node

  Рет қаралды 195,109

JSConf

JSConf

Жыл бұрын

Original talk "Getting closure on React Hooks" by Shawn "swyx" Wang at JSConf.Asia 2019 in Singapore. Find it at • Can Swyx recreate Reac...

Пікірлер: 83
@FERnandezJjuan
@FERnandezJjuan Жыл бұрын
That it’s not a HOOKk it’s just an state manager, it’s just taking advantage of closure
@ViieeS
@ViieeS Жыл бұрын
Can’t imagine why I need hooks in Node 😅
@YGaming18
@YGaming18 Жыл бұрын
Wtf
@okopyl
@okopyl Жыл бұрын
Can’t imagine why I need node to except Vercel when we all have Python
@ViieeS
@ViieeS Жыл бұрын
@@okopyl depends of use cases, it’s a powerful tool, I use both on my projects
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
useState and use effect are a way to achieve (functional) reactive programing (Which is the reactive that gives REACT it's name) It's a very usefull pattern that can simply state management a lot.
@oleh1
@oleh1 10 ай бұрын
@@sebastiangudino9377useState and useEffect are hacks because of React's poor design. The proper way to implement reactivity is to use an EventEmitter or an observer pattern(implemented by rxjs for example)
@arsheonix5893
@arsheonix5893 Жыл бұрын
feels like he's cloning createSignal in SolidJs
@RedStone576
@RedStone576 Жыл бұрын
this is just glorified mutable variable
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
Yeah, which is what useState is (Except that in react I also triggers a re-render). But pair it with useEffect, and now that variable can ejecute a function everytime it changes. And you have achieved reactivity. Which is pretty great
@oShinobu
@oShinobu 9 ай бұрын
​@@sebastiangudino9377 This is literally classes with getters and setters except more confusing
@sebastiangudino9377
@sebastiangudino9377 9 ай бұрын
@@oShinobu Yeah! "Reactivity" is just calling a function on getters and setters. It just so happens that such a simple concept gives you "Inmutable state". Which works well with functional programming and allows for very a very debuggable experience for projects with lots of state. Which is why front end frameworks use them
@pranjalagnihotri6072
@pranjalagnihotri6072 3 ай бұрын
Watched this back in college was amazing 😊
@marcusrehn6915
@marcusrehn6915 Жыл бұрын
When faced with a difficult problem, find a simpler one and solve that instead. This is not useState.
@oleksandrploskovytskyy1520
@oleksandrploskovytskyy1520 Жыл бұрын
Better to say it’s custom implementation of signals rather that hooks
@wlockuz4467
@wlockuz4467 Жыл бұрын
This is also not a signal. Its just an example of a closure.
@jma42
@jma42 Жыл бұрын
Its not a hook, its a signal implementation react what does there instead is save the state outside from the function, so when the hook runs again (when a component rerenders) it gets the new state. Something like this ```js let state = 0 ; function useState(s) { state = state || s const setState = (setter) => { state = setter(state) } return [state, setState] } const [count, setCount] = useState(1); console.log("initial state", count); setCount((n) => n + 1); console.log("stale state", count); // rerender const [count2, setCount2] = useState(1); console.log("changed state", count2); ```
@1conscience0dimension
@1conscience0dimension 11 ай бұрын
love you
@jeetviramgama4392
@jeetviramgama4392 Жыл бұрын
Can it be an example of a closure?
@mrajkishor331
@mrajkishor331 Жыл бұрын
How?
@buddimalliyanapathirana1767
@buddimalliyanapathirana1767 Жыл бұрын
​@@mrajkishor331 the state variable can be accessed after returning .
@rgrannell1
@rgrannell1 Жыл бұрын
Yes I believe so
@abhinandanchatterjee7315
@abhinandanchatterjee7315 9 ай бұрын
Yes. Here, after the useState function has finished execution, the setState function still retains access to its parent variable and is able to do manipulations on it. So it can be called a closure.
@MCasterAnd
@MCasterAnd Жыл бұрын
What kind of madman would want to put Reacts mess into Node?!
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
React is pretty cool. And represents a paradigm called reactive programing. Why is using RxJS good and React bad if the goal is reactivity in the end? (Very very very different things, I am aware, but both based arround the reactivity mindset and design patterns)
@und0
@und0 Жыл бұрын
Mess? React done right is a purely declarative user interface representation of immutable states. OOP patterns are the real messes, garbage paradigm that always lead to spaghetti 🤢.
@ufukbakan4741
@ufukbakan4741 Жыл бұрын
its not reacts mess, its an approach called reactive programming, and it started with RxJS not even with React
@stopPlannedObsolescence
@stopPlannedObsolescence 11 ай бұрын
sounds like a junior talking
@ryanlog
@ryanlog 10 ай бұрын
@@und0 React literally is a big MESS when compaed to other frameworks like Solid, Svelte, Vue etc and slower from all of them
@ShaharHarshuv
@ShaharHarshuv Жыл бұрын
Doesn't that defeats the purpuse if you don't "rerender"? what's the point?
@maelstrom-qw1jl
@maelstrom-qw1jl Жыл бұрын
Exactly. There's no concept of "re-rendering" whatsoever in a server-side context so React hooks are completely useless.
@sebastiangudino9377
@sebastiangudino9377 Жыл бұрын
Your render function can do other things. Like updating the database every time the variable changes This also opens the possibility for a useEffect hook. That triggers a function every time a variable gets updated. This would be a nice alternative to the observer pattern and things like RxJS Hooks are a weird idea in node. And there are other ways to archive things like reactivity there (Like the aforementioned RxJS). But it is really not a bad idea! It's worth exploring
@ShaharHarshuv
@ShaharHarshuv Жыл бұрын
​@@sebastiangudino9377Based on the example in this video, it's unclear how you would do such a thing. Assuming that you don't really want to touch the "useState" imlementation? One interesting thing that actually could be useful to replace rxjs in simple scenarios is signals. I've been looking at Angular's implementation lately at that looks pretty good. They manage to create connections between signals and effects because when you run a "compute" or "effect" call back they register a reference to that "node" so every signal you tried to read from is registered as a dependency of that node, so the subscription happens automatically. It's basically an easier version of rxjs that is easier to read and works for simple scenarios
@ganeshtowar8050
@ganeshtowar8050 Жыл бұрын
Where can we see full videos of this
@siyahulhaq7062
@siyahulhaq7062 10 ай бұрын
Use state in react using usereducer under the hood and reducer is managing re renders
@ryanlog
@ryanlog 10 ай бұрын
This is SolidJS actually
@martybando1668
@martybando1668 Жыл бұрын
so convoluted
@MrPlaiedes
@MrPlaiedes Жыл бұрын
So it's solid js...
@comadeycluster
@comadeycluster Жыл бұрын
Font ??
@shantanusharma4901
@shantanusharma4901 Жыл бұрын
Very good
@hasanassidiqin9497
@hasanassidiqin9497 10 ай бұрын
Return
@top-notchdiscovery1920
@top-notchdiscovery1920 Жыл бұрын
I'd call it useSignal
@afrid18
@afrid18 9 ай бұрын
What font is it?
@target500milliontradersinv5
@target500milliontradersinv5 11 ай бұрын
Ful lecture Vedio link?
@GamingGeek9000
@GamingGeek9000 Жыл бұрын
Epic
@MarianoAquino
@MarianoAquino Жыл бұрын
looks like FP discovered OOP =P
@ProtectedClassTest
@ProtectedClassTest Жыл бұрын
react devs are so crazy
@spookyconnolly6072
@spookyconnolly6072 Жыл бұрын
​@@ProtectedClassTest this sort of carry-on has been in literature for lisp/scheme/FP languages like SICP for decades. There is an old joke at MIT -- that i will not repeat in full -- where an initiate talks to a yogi and tries to get an answer whether closures or objects are better.
@princesiachin279
@princesiachin279 Жыл бұрын
@thomasneal7126
@thomasneal7126 9 ай бұрын
I concur
@thanirmalai
@thanirmalai Жыл бұрын
But how to trigger a render on to the screen when state is changed
@EatMyHacks
@EatMyHacks Жыл бұрын
useEffect!
@redhook777
@redhook777 Жыл бұрын
Call the virtual comparison function for virtual DOM inside setState function
@novanoskillz4151
@novanoskillz4151 Жыл бұрын
@@EatMyHacks so now he needs a video on how to recreate useEffect for node.
@basepasandhai1906
@basepasandhai1906 Жыл бұрын
React automatically re render components on state changes
@georgehammond867
@georgehammond867 8 ай бұрын
That's is really hard software
@Cookie-mv2hg
@Cookie-mv2hg 9 ай бұрын
What on earth is the font he is using ?
@awekeningbro1207
@awekeningbro1207 9 ай бұрын
Fira code
Жыл бұрын
that’s not how hooks work! with hook these 4 LoCs will print out 1 and 1
@kavehtehrani
@kavehtehrani 10 ай бұрын
That was amazing!
@hareeshbhittam7243
@hareeshbhittam7243 Жыл бұрын
What is the name of the speaker?
@raijinhasarrived
@raijinhasarrived Жыл бұрын
You can try to check in description
@buddimalliyanapathirana1767
@buddimalliyanapathirana1767 Жыл бұрын
​@@raijinhasarrived can't see description on the phone
@raijinhasarrived
@raijinhasarrived Жыл бұрын
@@buddimalliyanapathirana1767 I heard a legend about 3 dots on top right corner
@Nonsense116
@Nonsense116 Жыл бұрын
Lol why would you ever want to bring in reacts insanity into a non UI world
@helloluiis
@helloluiis Жыл бұрын
I’m in frontend, this is one of those times where frontend concepts just need to stay in the frontend 😅
@rahulpatil1382
@rahulpatil1382 Жыл бұрын
what is good to use useState in node js that venila js i am new to this and want to know more
@hodev632
@hodev632 Жыл бұрын
Making imutable setter and getter
@Khaled-bs7zc
@Khaled-bs7zc Жыл бұрын
Guys don't take this video seriously. It's meant to be serious but it's a waste of time.
@greendsnow
@greendsnow 8 ай бұрын
Can you please clone svelte too? Because react state management is awful
@ponysmallhorse
@ponysmallhorse 9 ай бұрын
I am a simple man. I see JS content I downvote! Python sends its regards.
@nathanhettige8465
@nathanhettige8465 Жыл бұрын
Bruh
@undefined_cat
@undefined_cat Жыл бұрын
It makes no sense
@Thassalocracy
@Thassalocracy Жыл бұрын
If you have to call "count" as a function then effectively you're creating a signal which means you're cloning SolidJS and not React. 😏
@complexity5545
@complexity5545 Жыл бұрын
This is why javascript sucks. So many gotcha's. I feel sorry for new programmers. You guys are taught the bad stuff from the beginning.
@zheil9152
@zheil9152 Жыл бұрын
How to slow down you performance of node code 101
@hasanassidiqin9497
@hasanassidiqin9497 10 ай бұрын
Usestate
@TheScriptPunk
@TheScriptPunk 8 ай бұрын
Lets normalize not using ameteur frameworks my guy. Node is awful as are the libs that exist within it
React Is A Backend Framework Now
8:30
Theo - t3․gg
Рет қаралды 180 М.
3 SIMPLE Python Project Ideas
0:42
HitraN the Programmer
Рет қаралды 317 М.
Do you have a friend like this? 🤣#shorts
00:12
dednahype
Рет қаралды 48 МЛН
The Worlds Most Powerfull Batteries !
00:48
Woody & Kleiny
Рет қаралды 19 МЛН
Cat story: from hate to love! 😻 #cat #cute #kitten
00:40
Stocat
Рет қаралды 15 МЛН
Omega Boy Past 3 #funny #viral #comedy
00:22
CRAZY GREAPA
Рет қаралды 33 МЛН
Learn React Hooks: useRef - Simply Explained!
12:42
Cosden Solutions
Рет қаралды 76 М.
🔥 JS Closures Explained Fast!
0:55
Dave Gray
Рет қаралды 142 М.
Someone sent me this VS Code extension on Twitter
0:35
Visual Studio Code
Рет қаралды 807 М.
This Is The Easiest React Hook
1:00
Web Dev Simplified
Рет қаралды 220 М.
How Vue.js as a web framework optimises rendering speed
1:00
TypeScript utility types you need to know
1:00
Steve (Builder.io)
Рет қаралды 108 М.
Learn useState In 15 Minutes - React Hooks Explained
15:45
Web Dev Simplified
Рет қаралды 1,1 МЛН
I tried 4 Full Stack Frameworks
1:05:16
Coding Garden
Рет қаралды 27 М.
Samsung or iPhone
0:19
rishton vines😇
Рет қаралды 9 МЛН
С Какой Высоты Разобьётся NOKIA3310 ?!😳
0:43
How much charging is in your phone right now? 📱➡️ 🔋VS 🪫
0:11
iPhone 15 Pro vs Samsung s24🤣 #shorts
0:10
Tech Tonics
Рет қаралды 10 МЛН
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 1,1 МЛН