React Hooks Tutorial - 5 - useState with array

React Hooks Tutorial - 5 - useState with array

Codevolution

5 лет назад

390,875 Просмотров

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


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

Krishna Agarwal
Krishna Agarwal - 10.07.2023 19:54

Where can I access the ppts?

Ответить
Baji Shaik
Baji Shaik - 29.05.2023 16:21

How to add items of array to existing array state object

Ответить
Atongba-Techs
Atongba-Techs - 19.04.2023 06:15

Hi!
Can someone tell me how to use useState with an object with an array attribute??

Ответить
Bhanu Prakash
Bhanu Prakash - 07.04.2023 22:02

Why we are pushing an object in line no. 7

Please any can know about it let me know....

Ответить
MBS
MBS - 05.02.2023 17:48

Excelente ! Muito Bem Explicado ! ! Parabéns pelos vídeos ! ! !

Ответить
Abdulrazaq Haroon
Abdulrazaq Haroon - 18.01.2023 14:00

A less complex way to do this is to use concat method: example below
You can rewrite your addItem method as thus;
const addItem=()=>{
setItems(items.concat({
id: items.length,
value: Math.floor(Math.random() * 10) + 1
}))
}

Ответить
Jomer Adrian A. Bug-os
Jomer Adrian A. Bug-os - 23.12.2022 05:50

Thank you vishwas

Ответить
mehul gupta
mehul gupta - 18.10.2022 12:19

My question is that after you append new data to the useState array the component should re-render, In case I have enough number of elements in the array to make it scroll then if i add one more to the useState array then will it re-render and the scroller moves to the top? In both the cases I want to know the reason

Ответить
Raj Banna Sa
Raj Banna Sa - 19.09.2022 14:27

thank you so much sir

Ответить
RoyBoyLab
RoyBoyLab - 30.08.2022 21:44

Do not miss the summary !!

Ответить
Worstenbroodje
Worstenbroodje - 25.08.2022 01:58

So you don't have to use the prevState setter function when you're spreading the object/array first? Am I right to think that spreading the state also gives the previous state and that's why you don't need it?

Ответить
shruu
shruu - 14.08.2022 11:47

why dont we use previous state in this case while updating the array

Ответить
Vignesh Gunasekaran
Vignesh Gunasekaran - 16.06.2022 06:43

1. setStateVar - will always gets its variable's type brackets.
setName( { } ), setItems( [ ]).
2. if array of items - always - map+arrow function Item + key
3. this video example is array of objects - id (obviously for keys), value - big note:

Ответить
Andrius Murauskas
Andrius Murauskas - 06.06.2022 19:25

Thank you very much for these excellent tutorials!

Ответить
Petalx3
Petalx3 - 23.05.2022 08:32

huge thanks for creating this content.. its really helpful 👍 i just figured out something because of YOUR EXISTENCE

Ответить
Muhammad Muneeb Ejaz
Muhammad Muneeb Ejaz - 24.04.2022 20:00

👍 great .

Ответить
ariel
ariel - 12.04.2022 13:40

dude you are amazing, I was so frustrated until I found this video. Thank you so much

Ответить
MTI Dicas
MTI Dicas - 17.02.2022 05:51

I don't understand English very good, but i understood this video, thanks for helping me😀😀

Ответить
Hypensterisk
Hypensterisk - 10.02.2022 09:58

Thank You, Your Video Is Very Helpful.

Ответить
Muhammad Ahmed
Muhammad Ahmed - 28.01.2022 10:05

thanks

Ответить
Julian Ifesiokwu
Julian Ifesiokwu - 18.01.2022 15:41

Very good explanation again. Keep up the good work boss.

Ответить
ahmed yousif
ahmed yousif - 13.01.2022 02:01

And if you want to delete an item ?

Ответить
yad
yad - 31.12.2021 19:40

Why not simply use "push" ?

Ответить
Giovanni Otr
Giovanni Otr - 28.12.2021 20:58

thank, that helped me a lot !

Ответить
oscp certificate
oscp certificate - 21.12.2021 12:55

Great series

Ответить
Paras Mehta
Paras Mehta - 01.12.2021 14:41

Can we use the push method for append instead of spread op?

Ответить
Ishan Khadka
Ishan Khadka - 28.11.2021 12:41

can we use 2 d array as a default item? if so how?

Ответить
Priyan Darshana
Priyan Darshana - 20.10.2021 12:14

you explain theories perfectly

Ответить
chintan gaur
chintan gaur - 14.10.2021 20:37

While creating a mini project for my university....I was stuck on this for 4 whole days..😭😭😭😭😭 such a basic thing i forgot... I am feeling as if i am the dumbest person alive... Thank you for this vidio it really helped me alot!!!!😭😭😭😭

Ответить
Nagendra Kamath
Nagendra Kamath - 09.10.2021 15:06

Wow it was good. But here the value of the id property is dependent on the previous array. Are we supposed to use the callback inside the setter?

Ответить
Afsana Zaman Nipa
Afsana Zaman Nipa - 04.10.2021 08:37

Appreciating your videos. thanks a lot.

Ответить
Vishal Gholap
Vishal Gholap - 14.09.2021 10:06

this shows how to add array elements, but how do change an element of array

Ответить
anish borkar
anish borkar - 02.09.2021 14:08

Currently I'm working on a project and I'm having an issue with setting the useState dynamically. I'm taking the key from the object return by the api and using them as a key for text field as I'm creating the dynamic curd operation can anyone please help me

Ответить
Dan M
Dan M - 30.08.2021 00:11

Great, what about delete and update?

Ответить
Bilal Ch
Bilal Ch - 28.07.2021 20:36

thank you so much, i was so frustrated while working with arrays in useState hook. You are no less than a savior of students. ❤❤

Ответить
Lara Rawf
Lara Rawf - 28.07.2021 17:46

God bless u

Ответить
Santoso Phone Tablet
Santoso Phone Tablet - 17.07.2021 10:32

what if we wanted to remove the number from the items array? how can we do that using useState? should we do it manually? or there is some way to do it?

Ответить
Mubasshir Khan
Mubasshir Khan - 28.06.2021 08:24

You save me from quiting React; Well explained

Ответить
FART BUG
FART BUG - 15.06.2021 14:50

You are my god!

Ответить
Blazing Tech
Blazing Tech - 08.05.2021 13:45

It was a great video on how we can add items, but how we can remove item from this array? i meant if we want to pop elements? Or can i insert a complete new array to the state variable?

my problem is that if I passed my changing array to the function, then my local array will be modified too.. Only one element will be remained in it

Ответить
Mohini Raut
Mohini Raut - 05.05.2021 15:52

God bless you sir

Ответить
BE_Drones
BE_Drones - 05.05.2021 11:28

What if you want to delete a specific item from an array and not add something ?

Ответить
Sensei
Sensei - 03.05.2021 08:20

Just wondering, how do you find a specific object to edit? Say id:5 you want to change the value. Is there a way to do that?

Ответить
Jesús Díaz
Jesús Díaz - 01.05.2021 05:54

what if i want to add a second value?

Ответить
Laughtale
Laughtale - 28.04.2021 13:27

y do i need a +1 in the 9th line

Ответить
N
N - 10.04.2021 16:00

Thank you so much.

Ответить
Ketan Mohide
Ketan Mohide - 08.04.2021 06:19

What about removing element from this array?

And hiw to initialize these with a null array? Do we still have to spread and then set with an empty array?

Would really appreciate if you could explain these things. Thanks

Ответить