No video

Use react hooks (useState) to toggle an active div.

  Рет қаралды 35,037

Thomas W. Li-Smith

Thomas W. Li-Smith

Күн бұрын

Пікірлер: 65
@jackjack121
@jackjack121 Жыл бұрын
You have no idea how much I've been losing my mind trying to figure this out. THANK YOU!!! You made seem so simple.
@youtubejhilkey8802
@youtubejhilkey8802 Жыл бұрын
Thank you so much. i was stucked for three days while implementing netflix faq section. your logic quickly solved my problem
@norrisdamianus5250
@norrisdamianus5250 3 жыл бұрын
after searching for several years, this is finally what I need
@user-cs3mq3rf8h
@user-cs3mq3rf8h 3 жыл бұрын
took me a decade
@theodurcan2
@theodurcan2 Жыл бұрын
Excellent. Clear, concise. Not unnecessary code, many tutorials miss the mark because they saturate the described process with basically bloat. Cheers,
@johnychinese
@johnychinese 2 жыл бұрын
I couldn't figure this out for 2 days Thanks alot man💯
@promisechidubemumeh7383
@promisechidubemumeh7383 2 жыл бұрын
Wonderful. This is a life saver bro. Keep saving lives 😂
@promisechidubemumeh7383
@promisechidubemumeh7383 2 жыл бұрын
Actually used it in my nav items though
@dilanli7491
@dilanli7491 3 жыл бұрын
This is exactly what I need! Thank you so much!
@uzairabdullah208
@uzairabdullah208 3 жыл бұрын
Exactly what I needed, well part of exactly what I needed!
@elodiemuller1185
@elodiemuller1185 2 жыл бұрын
If you want first object as default value (default color) do this : 1. Define a const outside the useState "appstate" (for exemple just before) const myObject = [{id :1, id: 2}] 2. in your useState "appState" change activeObject : null to activeObject: myObject[0] Enjoy :)
@chymera8466
@chymera8466 Жыл бұрын
It's not working. Can you double check? Thanks.
@elodiemuller1185
@elodiemuller1185 Жыл бұрын
​@@chymera8466 It's been 4 months so i'm not sure it's this part of my code but : const myStepMenu= [ { id: 1, name: "test1" }, { id: 2, name: "test2" }, { id: 3, name: "test3" }, ]; const [actualStep, setActualStep] = useState({ activeObject: myStepMenu[0], objects: myStepMenu, }); const toggleActive = (index) => { setActualStep({ ...actualStep, activeObject: actualStep.objects[index], }); };
@chymera8466
@chymera8466 Жыл бұрын
@@elodiemuller1185 Works now. Thank you!
@phanphongspvp
@phanphongspvp Жыл бұрын
@@elodiemuller1185 thankiu so much bro 💯
@grovemagnus9630
@grovemagnus9630 3 жыл бұрын
Thank you for the tutorial. This really helps with my React assignment.
@neets7519
@neets7519 2 жыл бұрын
Great teaching!! 👏👏👏👏👏👏👏👏
@allistermugaisi1625
@allistermugaisi1625 4 жыл бұрын
Thanks a lot, great video! The concept helped to solve my problem.
@rajatverma3122
@rajatverma3122 Жыл бұрын
Really helpful, thank you sir
@infernumw
@infernumw Жыл бұрын
dude i legit love u
@samyip
@samyip Жыл бұрын
I somehow like your mechanical keyboard clicking sound very much.
@carolinaklein4946
@carolinaklein4946 4 жыл бұрын
Great tutorial, even without sound
@Basil_Porphyrogenitos
@Basil_Porphyrogenitos 2 жыл бұрын
thank you so much, works in nextjs too, i used the classnames library tho to be able to use several classes
@dean55
@dean55 2 жыл бұрын
Fyi, when it imported useState that is correct now. Not sure which version of react this was allowed but I found this out a few months ago
@JumaanaAmjad
@JumaanaAmjad 3 жыл бұрын
Thank you so much for this tutorial!
@alexisk5978
@alexisk5978 Жыл бұрын
Thank you soooo much !!!
@annasahradyan9849
@annasahradyan9849 3 жыл бұрын
Thank you so much! , you are the best!!!
@kgblog2156
@kgblog2156 Жыл бұрын
Thank You so Much
@fonncatalina6464
@fonncatalina6464 3 жыл бұрын
THANKSSS! You save my ass 😂
@Goomie
@Goomie 3 жыл бұрын
So is there an issue with just using the state object without the spread operator? (...) Im aware of what spread does, but not sure the implications in this scenario.
@jesseneon1896
@jesseneon1896 3 жыл бұрын
Noisiest keyboard I've ever heard in my life
@Ilian1Burgos
@Ilian1Burgos 3 жыл бұрын
Thanks a lot bro!! suscribed!
@mianroshan3424
@mianroshan3424 2 жыл бұрын
Thank you!
@lezarus217
@lezarus217 Жыл бұрын
thank you so much
@jeanpierrekoff9134
@jeanpierrekoff9134 4 жыл бұрын
Love You for this
@whiterockjoe
@whiterockjoe Жыл бұрын
So, you compare references to the objects. mmm different than comparing values. Cool
@vickyr4178
@vickyr4178 3 жыл бұрын
Thanks Man❤️
@paramgandhi5768
@paramgandhi5768 2 жыл бұрын
it would have been better if you had showed this to indicate how active class changes in li items
@loveregefalk4049
@loveregefalk4049 2 жыл бұрын
Great stuff!
@mazennaeim7734
@mazennaeim7734 2 жыл бұрын
How can i select and unselect multiple boxes at the same time ? for example if i want to select 2 or more boxes?
@ThomasWSmith-wm5xn
@ThomasWSmith-wm5xn 2 жыл бұрын
kzbin.info/www/bejne/jmbLq4JvqMlnlbc&ab_channel=ThomasW.Smith
@mazennaeim7734
@mazennaeim7734 2 жыл бұрын
@@ThomasWSmith-wm5xn thank you so much exactly what I wanted for my project. All the best 🙏🏼
@philadelfiaproducao
@philadelfiaproducao 2 жыл бұрын
You saved my life
@paragrudani
@paragrudani 4 жыл бұрын
thanks god! I solved my big problem today! thank you!
@haoxianglin4257
@haoxianglin4257 Жыл бұрын
I would like to ask, when I complete the code according to the video tutorial, the effect of my project display is that I have to click twice to highlight, may I ask why?
@nikulyt3166
@nikulyt3166 2 жыл бұрын
Hard to watch on phone... No zoom in your screen where cursor follow? Mic is very fine
@milibaby1
@milibaby1 3 жыл бұрын
hero
@aluuusch
@aluuusch 2 жыл бұрын
Thanks for the tutorial. This keyboard is too loud though:D
@hoangcuongtran4606
@hoangcuongtran4606 3 жыл бұрын
thank you very much !
@HaNaxHeart
@HaNaxHeart 3 жыл бұрын
thanks man, you save me.
@jacqueskorb879
@jacqueskorb879 2 жыл бұрын
Thank you so much! How can I apply this to the blocks having different background images?
@rahu1gg
@rahu1gg 2 жыл бұрын
mean do you want different imgs and need a effect on that img when it is clicked?
@omrishooshan9784
@omrishooshan9784 3 жыл бұрын
how do you do it on a dynemic map which recieve values from a server and present them as li for example?
@uzairabdullah208
@uzairabdullah208 3 жыл бұрын
Please add the source code
@budiagung5245
@budiagung5245 3 жыл бұрын
Great content ! But can anyone explain elements on return its use for ?
@uzairabdullah208
@uzairabdullah208 3 жыл бұрын
I might be able to help if you explain your question a bit more
@imharshakumar
@imharshakumar 3 жыл бұрын
They are the names of the class.
@jenyaspace
@jenyaspace 2 жыл бұрын
How in TypeScript?
@aidanwalker3058
@aidanwalker3058 3 жыл бұрын
hey, nice tutorial :) how could i set the activeObject to the first box (id: 1) by default? I tried activeObject: tabState.objects[0] but its giving me an error
@greendayblinkmetal
@greendayblinkmetal 3 жыл бұрын
I need the same, have you solved it?
@aidanwalker3058
@aidanwalker3058 3 жыл бұрын
@@greendayblinkmetal I still haven't nope would be useful to know
@imharshakumar
@imharshakumar 3 жыл бұрын
Do as shown below, it worked for me!!! object: [ { id: 1, toggled: true, }, { id: 2, toggled: false, },] function toggleActiveStyles(index) { if ( appState.object[0] === appState.activeObject || appState.object[index].toggled ) { return "imgCont activeBg"; } else { return "imgCont inactiveBg"; } } function callToggleFun(index) { appState.object[index].toggled = false; changeState({ ...appState, activeObject: appState.object[index] }); }
@user-nb1mw2jj6p
@user-nb1mw2jj6p 3 жыл бұрын
@@imharshakumar It did not work for me, but after I changed appState.object[0] to appState.object[index], it worked fine. Thank you anyway.
@kevincornellius
@kevincornellius 2 жыл бұрын
@@imharshakumar it did work very well for me but i think change the appState.object[index].toggled = false; to appState.object[0].toggled = false; or else it wont work
@abhishekverma2568
@abhishekverma2568 3 жыл бұрын
code daal do sir
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 473 М.
Learn React Hooks: useRef - Simply Explained!
12:42
Cosden Solutions
Рет қаралды 96 М.
So Cute 🥰
00:17
dednahype
Рет қаралды 43 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 61 МЛН
Protected Routes in ReactJS - React Router Dom
19:03
PedroTech
Рет қаралды 67 М.
Web scraping with node, axios and cheerio
8:04
Thomas W. Li-Smith
Рет қаралды 10 М.
Context API in react | get the concept
29:00
Hitesh Choudhary
Рет қаралды 55 М.
6 State Mistakes Every Junior React Developer Makes
15:53
Lama Dev
Рет қаралды 266 М.
Learn useState In 15 Minutes - React Hooks Explained
15:45
Web Dev Simplified
Рет қаралды 1,1 МЛН
React Hooks Crash Course (useMemo, useCallback and more).
31:49
developedbyed
Рет қаралды 84 М.
Learn React useReducer Hook with Examples
14:19
Lama Dev
Рет қаралды 175 М.
10 React Antipatterns to Avoid - Code This, Not That!
8:55
Fireship
Рет қаралды 742 М.
Toggle Class On Click using React JS | React JS Tutorial
7:29
WebStylePress
Рет қаралды 35 М.
So Cute 🥰
00:17
dednahype
Рет қаралды 43 МЛН