4 Beginner React States Mistakes to AVOID

  Рет қаралды 7,655

PedroTech

PedroTech

Күн бұрын

Пікірлер: 21
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
The first 1,000 people to use the link will get a 1 month free trial of Skillshare: skl.sh/pedrotech08221
@ivodelev9794
@ivodelev9794 2 жыл бұрын
Hi, great video Pedro! On the last "mistake" what I would do is group the state in to single object and have 1 setter for the entire state, instead of unnecessarily complicate the code with useReducer unless it becomes more complex with deep nested objects and arrays.
@Linkdu-pp5nl
@Linkdu-pp5nl 2 жыл бұрын
What do you think to use a single state like this : const [login, setLogin] = useState(initialState) And then setLogin({...login, key:value}) To update the value
@levaniakobidze8202
@levaniakobidze8202 2 жыл бұрын
Great video.Thanks Pedro.
@waleedsharif618
@waleedsharif618 2 жыл бұрын
At 7:36 you said dont create state for it, but what if we want to change that data coming from useQuery and show that changed data (for example filtering), then we need to set state for it right?
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Great question! You can just create a variable for the changed data. FOr example, imagine the data we get back from the useQuery is called `data`. Now imagine we want to change that data by filtering. We can just create a new variable: const newData = data.filter(()=>...)
@sanketss84
@sanketss84 2 жыл бұрын
Will this rerender the component on refetch trigger by react query?
@waleedsharif618
@waleedsharif618 2 жыл бұрын
@@PedroTechnologies but if we want to update that data then we should use useState ?
@сойка-и8й
@сойка-и8й 2 жыл бұрын
@@waleedsharif618 the data is coming from an API all you can do is display it. why will you want to mutate data coming from an API ??
@waleedsharif618
@waleedsharif618 2 жыл бұрын
@@сойка-и8й if i want to get that data from api and in useEffect add something to it then display, so useState is needed?
@zainabideen8144
@zainabideen8144 2 жыл бұрын
Always Fantastic stuff! Looking forward to more amazing videos
@Matt-dt7cf
@Matt-dt7cf 2 жыл бұрын
so how do you force setState to work synchronously?
@ghosriderxD
@ghosriderxD 2 жыл бұрын
just copy the content to a local variable and work with that variable and set the state once at the end of the function
@сойка-и8й
@сойка-и8й 2 жыл бұрын
Using function to update state const [age, setAge] = useState(0) use setAge((prev)=> prev+1) instead of setAge(age+1)
@alpaca_growing_kit
@alpaca_growing_kit 2 жыл бұрын
Why would you not just go all the way and get redux toolkit implemented if you need the login logic elsewhere in the application? UseReducer bugs me a bit, because I think it's easier to just spend 5-10 minutes setting up redux toolkit, especially professionally so it scales better.
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
In this case, the useReducer is used for onlhy a specific part of the app, not to mention that it built into react so if you were to use redux toolkit for this it would be better to use the useReducer. (smaller size and built in)
@alpaca_growing_kit
@alpaca_growing_kit 2 жыл бұрын
@@PedroTechnologies yeah definitely in this case, but what I mean is that there's few situations where you need useReducer and cannot just use redux toolkit in a professional setting, because it will scale better. But yeah in niche situations its better to just use the reducer hook.
@eloualihmade7071
@eloualihmade7071 2 жыл бұрын
I don't know how i can thank you, but really thank you so much ❣️
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Happy to help!
@fromthefuture1238
@fromthefuture1238 2 жыл бұрын
how to npx create-react-app adding pckg with yarn, mine is adding pckg with npm
@hamad5141
@hamad5141 2 жыл бұрын
What vs theme are you using?
The Ultimate Web Developer Roadmap
17:12
PedroTech
Рет қаралды 17 М.
React Hooks Course - All React Hooks Explained
1:26:21
PedroTech
Рет қаралды 1,1 МЛН
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 59 МЛН
What's in the clown's bag? #clown #angel #bunnypolice
00:19
超人夫妇
Рет қаралды 12 МЛН
НИКИТА ПОДСТАВИЛ ДЖОНИ 😡
01:00
HOOOTDOGS
Рет қаралды 1,7 МЛН
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 59 МЛН
All The JavaScript You Need To Know For React
28:00
PedroTech
Рет қаралды 632 М.
UseEffect Mistakes Every Beginner Should Avoid
18:05
PedroTech
Рет қаралды 29 М.
Top 6 React Hook Mistakes Beginners Make
21:18
Web Dev Simplified
Рет қаралды 576 М.
State Managers Are Making Your Code Worse In React
13:33
Web Dev Simplified
Рет қаралды 191 М.
React Interview Questions | Beginner to Advanced
26:42
PedroTech
Рет қаралды 36 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 719 М.
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 59 МЛН