4 Beginner React States Mistakes to AVOID

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

PedroTech

PedroTech

Күн бұрын

The first 1,000 people to use the link will get a 1 month free trial of Skillshare: skl.sh/pedrote...
In this video I will go over 4 reactjs states mistakes you should avoid.
Join our Discord: / discord
🚀 Learn ReactJS By Building 6 Projects: codedamn.com/l...
🐙 GraphQL Course: codedamn.com/l...
► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech
Social
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Website: machadopedro.com
Linkedin: / machadop1407
Instagram: / _pedro.machado_
Github: github.com/mac...
Business Email: pedro@pedrotech.co
Tags:
- ReactJS Tutorial
- ReactJS and MySQL
- NodeJS Tutorial
- React States
#reactjs #states

Пікірлер: 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 Жыл бұрын
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
@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
@user-og7de8ih4f
@user-og7de8ih4f 2 жыл бұрын
Using function to update state const [age, setAge] = useState(0) use setAge((prev)=> prev+1) instead of setAge(age+1)
@fromthefuture1238
@fromthefuture1238 2 жыл бұрын
how to npx create-react-app adding pckg with yarn, mine is adding pckg with npm
@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 ?
@user-og7de8ih4f
@user-og7de8ih4f 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 жыл бұрын
@@user-og7de8ih4f if i want to get that data from api and in useEffect add something to it then display, so useState is needed?
@eloualihmade7071
@eloualihmade7071 2 жыл бұрын
I don't know how i can thank you, but really thank you so much ❣️
@PedroTechnologies
@PedroTechnologies 2 жыл бұрын
Happy to help!
@levaniakobidze8202
@levaniakobidze8202 2 жыл бұрын
Great video.Thanks Pedro.
@zainabideen8144
@zainabideen8144 2 жыл бұрын
Always Fantastic stuff! Looking forward to more amazing videos
@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.
@hamad5141
@hamad5141 2 жыл бұрын
What vs theme are you using?
The Ultimate Web Developer Roadmap
17:12
PedroTech
Рет қаралды 17 М.
UseEffect Mistakes Every Beginner Should Avoid
18:05
PedroTech
Рет қаралды 29 М.
Dad gives best memory keeper
01:00
Justin Flom
Рет қаралды 20 МЛН
Whoa
01:00
Justin Flom
Рет қаралды 55 МЛН
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 474 М.
6 State Mistakes Every Junior React Developer Makes
15:53
Lama Dev
Рет қаралды 266 М.
All The JavaScript You Need To Know For React
28:00
PedroTech
Рет қаралды 608 М.
10 React Antipatterns to Avoid - Code This, Not That!
8:55
Fireship
Рет қаралды 742 М.
Why you SHOULD be using TypeScript with React
14:55
PedroTech
Рет қаралды 25 М.
5 Pro-Level React Do's & Don'ts
30:06
Traversy Media
Рет қаралды 176 М.
React Interview Questions | Beginner to Advanced
26:42
PedroTech
Рет қаралды 29 М.
State Managers Are Making Your Code Worse In React
13:33
Web Dev Simplified
Рет қаралды 180 М.