Rebuilding Jotai State Manager for React in 20 Minutes!

  Рет қаралды 31,344

Jack Herrington

Jack Herrington

Күн бұрын

Code: github.com/jherr/jotai-rebuild
Daishi's Tweet: / 1484835169475653634
Daishi's course on Jotai: daishi.gumroad.com/l/learn-jotai
Jotai Docs: jotai.org/docs
👉 I'm a host on the React Round-Up podcast: devchat.tv/podcasts/react-rou...
👉 Don't forget to subscribe to this channel for more updates: bit.ly/2E7drfJ
👉 Discord server signup: / discord
👉 VS Code theme and font? Night Wolf [black] and Operator Mono
👉 Terminal Theme and font? oh-my-posh with powerlevel10k_rainbow and SpaceMono NF
0:00 Introduction
1:04 Jotai Introduction
2:46 Creating The Core Atom
5:21 Creating The Hooks
10:32 Enabling Computed Atoms
15:48 Enabling Async Atoms
19:36 Outroduction

Пікірлер: 133
@bekirs4240
@bekirs4240 Жыл бұрын
This type of content is exactly what we need. We don't need more beginner stuff, this is where you learn
@puneetsingh9678
@puneetsingh9678 Жыл бұрын
💯 !
@MahbuburRahman-uc7np
@MahbuburRahman-uc7np Жыл бұрын
For a Junior/Mid-level developer, this Content is GOLD. This is the type of content someone like me needs to level up.
@ionelLupu_
@ionelLupu_ Жыл бұрын
I have 10 years experience of web development and I still find this type of content GOLD 😂
@dprophecyguy
@dprophecyguy Жыл бұрын
Will appreciate more build from scratch videos.
@WikiPeoples
@WikiPeoples Жыл бұрын
This is EXACTLY the content we NEED! No more noobie stuff, but dive into deeper topics like this. LOVE IT!
@HeinekenLasse
@HeinekenLasse Жыл бұрын
Amazing! The computed atom part was a bit tough to follow, but that's exactly the type of content we need, something a bit more challenging than the never ending newbie tutorials.
@karolwons8566
@karolwons8566 Жыл бұрын
What a great video! I look forward to seeing more advanced stuff like this on your channel.
@revillsimon
@revillsimon Жыл бұрын
Your content keeps getting better, Jack! Fascinating, and I especially like how you explain the reasoning about the types. 😊
@geralt36
@geralt36 Жыл бұрын
Ooof that was some fab content Jack. Learned so much. Thanks a ton!
@andrerego2611
@andrerego2611 Жыл бұрын
That was amazing! I've never seen content like this, thanks!
@awekeningbro1207
@awekeningbro1207 Жыл бұрын
I really love videos like this. Thanks Jack! This really helps us to understand the core better. Really love to see more videos like this
@manny8156
@manny8156 Жыл бұрын
I’ve learned most of the advanced things in react from you. Thank you so much!
@igboanugwocollins4452
@igboanugwocollins4452 Жыл бұрын
This is tricky and exciting at the same time! Thank you very much
@mgrahim5018
@mgrahim5018 Жыл бұрын
We need more of this. Now, I'll probably have to come back to this video untill I grasp all the concept. Thank you
@joshreynolds4164
@joshreynolds4164 Жыл бұрын
Hands down best channel on youtube right now in the React space. We thank you!
@Fedjz
@Fedjz Жыл бұрын
What such quality content! Glad to be subscribed to this channel :)
@umitdemir3741
@umitdemir3741 Жыл бұрын
You and your contents are really amazigng. Thanks for all of them!
@Dgiulian
@Dgiulian Жыл бұрын
I loved the video. Keep making this content. This is pure gold
@petrhavlik
@petrhavlik Жыл бұрын
Excellent stuff Jack, please keep going!
@Echoes2165
@Echoes2165 Жыл бұрын
Another amazing tutorial. This one might take 2 rewatches and reimplementing it myself before it really clicks in - can't wait!
@MsPrakhar12
@MsPrakhar12 Жыл бұрын
pretty awesome 🔥 Amazing work
@JGBSolutions
@JGBSolutions Жыл бұрын
I liked it. I gotta watch it more times to get it right. Keep 'em coming.
@bartek...
@bartek... Жыл бұрын
Thanks for your work. Another very valuable video.
@Dev-Coder
@Dev-Coder Жыл бұрын
Amazing content!❤️
@qodesmith520
@qodesmith520 Жыл бұрын
My man, you got the like, subscribe, AND I rang the bell. This was amazing.
@vonderklaas
@vonderklaas Жыл бұрын
Thanks Jack, captivating as always!
@kasvith
@kasvith Жыл бұрын
Great stuff as always
@vasilicampuica6428
@vasilicampuica6428 Жыл бұрын
Great content, Jack!
@erikslorenz
@erikslorenz Жыл бұрын
I've been loving Jotai thanks Jack
@vcothur7
@vcothur7 Жыл бұрын
This is amazing!
@dhaw
@dhaw Жыл бұрын
just amazing !!!
@user-jb9wp9vf3h
@user-jb9wp9vf3h 5 ай бұрын
Enjoyed your video, thank you.💯
@WrongAkram
@WrongAkram Жыл бұрын
You’ve easily become my favorite creator here!
@permanar_
@permanar_ Жыл бұрын
What? Are you finally remember your YT password? You both are my favs content creator bro, I hope you keep that good stuff coming. I've been waiting for those another Framer Motion stuff. And maybe some GSAP if possible! Haha.
@aslamjm
@aslamjm Жыл бұрын
when i look into youtube webdev tutorial hell all i see are baby level react tutorials with todolist like application. This is the fresh and interesting content most people here need. Thanks Jack keep up the good work
@thiagomoraes791
@thiagomoraes791 Жыл бұрын
great content 😀
@tolgask2812
@tolgask2812 Жыл бұрын
wonderful content :D
@lautarodapin
@lautarodapin Жыл бұрын
that was so cool! I didn't imagine that it was so simple, like a svelte stoore
@jamshediqbal7936
@jamshediqbal7936 Жыл бұрын
Good channel to learn advanced topics 🎉
@shivamjhaa
@shivamjhaa Жыл бұрын
This is really really cooool!
@elmalleable
@elmalleable Жыл бұрын
jotai will be fun, will solves some promise headaches on a project
@rameshramesh-bd2wu
@rameshramesh-bd2wu Жыл бұрын
Need more videos like this talking about internal function of the system is literally watching a crime thriller movie
@luizpaulonascimento9162
@luizpaulonascimento9162 Жыл бұрын
awesome content
@mohamed_elmardi
@mohamed_elmardi Жыл бұрын
Amazing!
@lilpodbebe
@lilpodbebe Жыл бұрын
Pure gold!
@feitan8745
@feitan8745 Жыл бұрын
Impressive as always, currently i'm using custom reducers for my apps and the setup is quite the same.
@mdjaman7348
@mdjaman7348 Жыл бұрын
love you bro
@gencomer
@gencomer Жыл бұрын
Very impressive
@jasondavis87
@jasondavis87 Жыл бұрын
I love this!!!
@saiyanrivals
@saiyanrivals Жыл бұрын
Awesome
@eliasimokhai
@eliasimokhai Жыл бұрын
This was tough and fun
@realbigsquid
@realbigsquid Жыл бұрын
100 percent mind blown
@ivanglpz
@ivanglpz Жыл бұрын
Nice Video about jotai core. I would like to see to daishi kato and Jack Herrington talking about jotai in the future.
@deamorta6117
@deamorta6117 Жыл бұрын
GOLD GOLD GOLD content
@jeresalem
@jeresalem Жыл бұрын
Awesome.
@fricze
@fricze Жыл бұрын
cool stuff
@abhishekvishwakarma9045
@abhishekvishwakarma9045 Жыл бұрын
Thanks a ton, each video you made is a new learning experience for me , btw I think we can use the `instanceof` operator to check if the return newValue is a Promise object like so ``` if (newValue instanceof Promise) { // Promise } else { // not a promise } ```
@rkrupinski
@rkrupinski 11 ай бұрын
Great video, Jack! I think I see a subtle bug in the implementation though. Looks like we're continuously re-subscribing (in the `get` function), which makes the number of subscriptions grow exponentially.
@fhucko
@fhucko Жыл бұрын
I am currently using Zustand in project i work on, but Jotai seems even more simple. I will try to switch to it. Thank you
@tawalioualao7444
@tawalioualao7444 Жыл бұрын
Zustand is more centralized store while Jotai is small store (like react context) so it's depends on your need
@rebeccakeller4666
@rebeccakeller4666 Жыл бұрын
I'm using both in same project. I much prefer jotai over all (and useReducerAtom sure does blur the line too). But when I thought I'd go all-jotai I got bit by rerenders. With zustand you can use a single properties of a huge single object and subscribers (ie useFooBarStore)only get updates if the selected prop changes. With jotai, all subscribers (even with derived atoms) get pinged. That to me is the biggest difference. Still much prefer jotai but as I was basically trying to figure out how to reimplement zustand in jotai I reverted that particular but and use both, preferring jotai as a rule though. There is a jotai library that is supposed to allow you to use sub atoms like that but I couldn't get it working but maybe I'm just dumb idk
@fhucko
@fhucko Жыл бұрын
@@rebeccakeller4666 I just checked documentation, I think you are supposed to slect part of atom using focusAtom function. Or selectAtom for read only data.
@fhucko
@fhucko Жыл бұрын
@@tawalioualao7444 I use zustand with many decentralized stores using useState. I have also few global stores, but most are scoped in components.
@rebeccakeller4666
@rebeccakeller4666 Жыл бұрын
@Filip Hučko ah yes thats he library I was thinking of (focusAtom is in another npm package and i cant recall the problems I had exactly). I think actually that selectAtom (which is in jotai primary package) mightve done the trick but I missed the equality operator function as the third parameter - so perhaps there is a cleaner way to do it.
@WajuAbolarin
@WajuAbolarin Жыл бұрын
This is amazing content. and to get this for free. thanks Jack!
@user-qp4fm7ue6y
@user-qp4fm7ue6y Жыл бұрын
Your content is really great, And I really like it. This video in particular is exactly what I needed, so I agree with all the other commenters. By the way, it is important to note here in a prominent place that the code is not ready as it is, and its actions grow exponentially, very quickly it will cause every key press to millions of actions and the browser to crash, because within the get function you are always subscribing but never unsubscribing, So each run is subscribing again the existing function, which are getting doubled each run. the solution is either to add a key to each atom registration as in the original recoil and then check if it already exists, or use JSON.stringify on the ATOM and check if it already exists using another set.
@joshreynolds4164
@joshreynolds4164 Жыл бұрын
Good point. Could you provide an example of this?
@elmalleable
@elmalleable 3 ай бұрын
@@joshreynolds4164 learnt that the hard way rebuilding this with rxjs, solution is keep a set or map of subscriptions and only subscribe once for the specific atom, add it to the list of subscribed atoms and do not subscribe if a subsciption already exists for it, found that out through simple test cases i made
@user-pw4oq9cs3l
@user-pw4oq9cs3l 6 ай бұрын
amazing video, thank you !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@Ste00I
@Ste00I Жыл бұрын
I actually use the sidebar always on the right in VSCode. It just feels more natural to me glancing on the right, instead of on the left.
@andrepadez
@andrepadez Жыл бұрын
you're a GOD among men
@bosung90
@bosung90 6 ай бұрын
Would love to see jotai's onMount as well as jotai-effect
@ToreyLittlefield
@ToreyLittlefield Жыл бұрын
Challenge accepted 🔥🔥
@CrazyWolf132
@CrazyWolf132 Жыл бұрын
It would be super cool if you could do the same kind of video for creating a system like `react-hook-form`.
@samsurya283
@samsurya283 Жыл бұрын
Awesome, could you please make a video on two way binding
@streamoverlayprocodes6890
@streamoverlayprocodes6890 Жыл бұрын
aha! I see you doing semantic names for type definitions on generics! someone is watching Matt Pocock
@download333
@download333 Жыл бұрын
One little hair change and my man looking like the mayor of Pleasantville
@parassharma7041
@parassharma7041 Жыл бұрын
A scientist keeps experimenting with react 😃
@charliematters
@charliematters Жыл бұрын
That was great and really easy to follow. Is that copilot doing all the magical autocompletion?
@jherr
@jherr Жыл бұрын
Yep. With a serious helping of me since that was the second time around so Copilot was repeating a lot of my back to myself. :)
@charliematters
@charliematters Жыл бұрын
@@jherr I did think it was even cleverer than I expected!
@greatauntmuriel
@greatauntmuriel Жыл бұрын
explorer on the right is superior
@MouseCodes
@MouseCodes Жыл бұрын
hey jack nice content, I hope you make a video about how to make a profile for users and enable them to update their info with zustand and nextjs protected routes. this would be really helpful.
@jherr
@jherr Жыл бұрын
That seems awfully specific. Is that what you are working on currently?
@MouseCodes
@MouseCodes Жыл бұрын
Yeah and KZbin has nothing like that most tuts only scratch the surface of zustand which makes it hard to use this un-opinionated library.
@MouseCodes
@MouseCodes Жыл бұрын
It's specific but it is needed for every project whether it is e-commerce, freelancing site, social media, etc...
@jherr
@jherr Жыл бұрын
@@MouseCodes No worries. And you're right, auth is needed for pretty much every site. Have you tried NextAuth? Generally I let that manage the user and then on the profile page I would get the profile data during SSR and preload react-query with the profile information, then use RQ later to update it through an authorized API route.
@MouseCodes
@MouseCodes Жыл бұрын
That's exactly what I am trying to achieve, that solution was definitely inspired by your videos.
@thecodecatalyst
@thecodecatalyst Жыл бұрын
File tree on the right is the way
@GachiTscho
@GachiTscho Жыл бұрын
This should go to Jotai official docs🤣
@jr-hp7er
@jr-hp7er Жыл бұрын
This is awesome. I love this. This is precisely what is needed. I have 1 question where I want to implement a Modal window with the form elements, and when I close the window and re-open it again, I want to display data selected by the users previously. Can this help or do we require some sort of persistence here? I have tried with redux, wrapping the parent component above the modal, and it works fine? But want to move from redux to something like this
@jherr
@jherr Жыл бұрын
I would strongly recommend going with Jotai instead of using this code. This code was presented as a way to more deeply understand how this one particular model of state management works, not to actually replace Jotai. TBH, any state manager, including Redux, will handle the scenario you present. I recommend pushing on with redux. Use the redux toolkit if you aren't already. And if you get stuck on modeling then this then ask for assistance on Reactiflux, but make sure to follow their rules before posting.
@jr-hp7er
@jr-hp7er Жыл бұрын
@@jherr Thank you so much 🙏
@bradleyangusmorgan7005
@bradleyangusmorgan7005 8 ай бұрын
🎯 Key Takeaways for quick navigation: 00:00 🚀 Jotai is introduced as an atomic state manager for React, similar to Recoil, and the video begins with a challenge to rebuild it. 01:09 🧩 Demonstrates how atoms in Jotai can be any data type and used throughout a React application, providing a global state. 03:15 🔧 The structure of an atom is outlined, including methods for getting, setting, and subscribing to changes in its value. 05:17 🎣 Explains the creation of the `useAtom` hook in Jotai, which integrates the atom with React's state management. 08:00 ✨ Showcases the use of the `useSyncExternalStore` hook to simplify state synchronization within the React ecosystem. 09:36 🌐 Jotai allows for the creation of global data that is easily accessible throughout the component hierarchy and is simple to implement. 10:35 ➕ The 'total salary atom' in Jotai can calculate derived state, such as summing a salary and a bonus, using getter functions to access other atoms' values. 12:05 🔄 Jotai's atom types can be dynamic, meaning an atom can be a function that computes its value based on other atoms, and TypeScript can be used to ensure type correctness. 14:10 🔄 The video demonstrates how to ensure atoms re-compute their values when dependencies change and how to avoid unnecessary computations. 15:44 ⏳ Jotai supports asynchronous atoms, which can perform operations like data fetching and automatically handle promise resolution. Made with HARPA AI
@Shifter21000
@Shifter21000 Жыл бұрын
This is a great help, Jack. How does Jotai and state management work together with SSR in NextJS. There are few hooks for this need, some go with providers, but is there an established pattern here.
@jherr
@jherr Жыл бұрын
If you have global atoms it's pretty easy. I haven't checked with Jotai's contextual stuff, probably still works. Basically any state manager that has external (non-hook) access is going to work with RSCs.
@awekeningbro1207
@awekeningbro1207 4 ай бұрын
14:48 I think there a memory leak issue in the get function because everytime salary or bonus changes, it will keep stacking new subscriber function, I think we need to call unsubscribe function inside the subscribe callback in order to fix that
@aliarslanansari
@aliarslanansari Жыл бұрын
In a follow up video, can you write test for this code using JEST or any of your preferred testing library?
@ayushjain7023
@ayushjain7023 Жыл бұрын
Hey Jack, do we need to have atom dependency inside useEffect?
@streamoverlayprocodes6890
@streamoverlayprocodes6890 Жыл бұрын
the code explorer to be on the right feels a bit unnatural because our romantic language disposition is to look from left to right, and when I look for files, my brain maps everything from the left. But everything is about user preferences 😀, I won't mandate you to eat soup with a fork :)
@rodneydin
@rodneydin Жыл бұрын
Would it be great if you had a discord server 🎉
@jherr
@jherr Жыл бұрын
Turns out, I do: discord.gg/sae4SWPAFN
@michaelscofield2469
@michaelscofield2469 Жыл бұрын
Please make a video about how to setup react, typescript, eslint, prettier
@claus4tw
@claus4tw Жыл бұрын
Npx create-t3-app
@pollettoimpanato
@pollettoimpanato Жыл бұрын
18:35 my honest reaction every time “unexpected { at line 189” disappears after a random reload (there are only 10 lines of code)
@thomashermant9321
@thomashermant9321 Жыл бұрын
Hi ! First of all you do a great job on your content ! I try you code in my NextJs application. Everything working fine until I use an atom with a getter function. My Set reached is maximum capacity. When I put a log between line 23 and 24 in jotai.ts After some inputs manipulation I got thousand even million logs. Any idea to improve it ?
@Seedzification
@Seedzification Жыл бұрын
yea it's probably missing a useref or a usecallback somewhere?
@adityapanday007
@adityapanday007 Жыл бұрын
Which extension used for auto suggestions?
@jherr
@jherr Жыл бұрын
GitHub Copilot
@codingleo
@codingleo Жыл бұрын
First here woooooohoooo
@andrewc8125
@andrewc8125 Жыл бұрын
I think it is time to migrate from Recoil to Jotai
@Maybehassanawad
@Maybehassanawad Жыл бұрын
Can you please rebuild Valtio🤩
@jherr
@jherr Жыл бұрын
At it's most basic I can (and will) do that as a short.
@frontend_ko
@frontend_ko Жыл бұрын
Zustand is the next, sir?
@adamjamiu6764
@adamjamiu6764 Жыл бұрын
Hi Jack 😊. What is the name of your code editor font family
@jherr
@jherr Жыл бұрын
JETBrains Mono
@Poohbify
@Poohbify Жыл бұрын
:[[ Eventually I will understand this.
@VKD007
@VKD007 Жыл бұрын
I thought you will use signals and jotai
@jherr
@jherr Жыл бұрын
I made this video before the "great signal boom of early 2023" :) But I wouldn't have added them anyway, since I really don't think ref-patching React is a good idea.
@VKD007
@VKD007 Жыл бұрын
I really liked jotai though, ive seen your video. Jotai for async state and signals for granular updates.
@kerodfresenbetgebremedhin1881
@kerodfresenbetgebremedhin1881 Жыл бұрын
Sir, you are the best fit for intermediate to high skill programming content. I have no right to impose upon you content restrictions, but in my opinion you and obviously content consumers like me would be best served in this niche.
@jherr
@jherr Жыл бұрын
Don't worry, I'll always be producing some medium to advanced content on a regular basis.
@DjLeonSKennedy
@DjLeonSKennedy Жыл бұрын
You need to create payable courses, your explanation is perfect!
@_RobTheRed_
@_RobTheRed_ Жыл бұрын
Next for UI/UX with rebuild/refresh of react drag n drop? 🫣
Mastering React Memo
26:56
Jack Herrington
Рет қаралды 133 М.
3 React Mistakes, 1 App Killer
14:00
Jack Herrington
Рет қаралды 114 М.
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 92 МЛН
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 118 МЛН
你们会选择哪一辆呢#short #angel #clown
00:20
Super Beauty team
Рет қаралды 48 МЛН
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 161 МЛН
Smarter and Simpler React State
26:46
Jack Herrington
Рет қаралды 55 М.
Five React App Killing Anti-Patterns 🪦😱
12:47
Jack Herrington
Рет қаралды 31 М.
The Heart of React || How React works under the hood
10:32
AI Bruise
Рет қаралды 14 М.
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 82 М.
Знакомство с Zustand - лучшей заменой Redux
29:35
Михаил Непомнящий
Рет қаралды 29 М.
Picking From 20 React State Managers
35:18
Jack Herrington
Рет қаралды 84 М.
Mastering React Context: Do you NEED a state manager?
37:26
Jack Herrington
Рет қаралды 97 М.
Jotai Async
18:47
Sinclair Software
Рет қаралды 1,3 М.
What State Management Library Should I Use with React?
9:27
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 461 М.
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 7 МЛН
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 106 М.