ReactJS Tutorial - 11 - setState

ReactJS Tutorial - 11 - setState

Codevolution

5 лет назад

732,197 Просмотров

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


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

@shyngysbek6907
@shyngysbek6907 - 05.11.2023 01:12

How do you format the code?

Ответить
@lathagm666
@lathagm666 - 24.10.2023 19:22

completed 11th Video. Thank you 🙂

Ответить
@W4lkthroughWizard
@W4lkthroughWizard - 03.10.2023 21:38

Do you need to bind the state if you use no arrow function?

Ответить
@whoots6967
@whoots6967 - 20.08.2023 23:49

Coming from all other languages of programming could you please explain is prevState a reserved word? you say pass it as a parameter however I do not see where prevState is defined. Thanks!

Ответить
@dadasajad8741
@dadasajad8741 - 14.08.2023 14:13

Sir, you are the best.

Ответить
@peteremmanuelkitsamba4867
@peteremmanuelkitsamba4867 - 31.07.2023 01:40

what the heeeelll, I had to first try out that rce cheat-code

Ответить
@koushikhalder1579
@koushikhalder1579 - 16.06.2023 15:36

Thanks to vishwas, ur knowledge help me to do my office project.
Thank You

Ответить
@engkunasya
@engkunasya - 02.06.2023 09:43

For the CONSOLE element and STATE (DISPLAY) to be counting synchronously, why don't you just add +1 in the console.log ?

console.log (this.state.count +1)

Ответить
@ludangupta8505
@ludangupta8505 - 22.05.2023 17:39

new comers use, functional componet with useState instead

Ответить
@thantzinwin7215
@thantzinwin7215 - 21.05.2023 14:27

I feel I chose the right channel for React Tutorial

Ответить
@Tejaswini-mm1yc
@Tejaswini-mm1yc - 10.05.2023 19:16

As a beginner its very confusing🤕😥

Ответить
@williamwang-wc8mp
@williamwang-wc8mp - 02.04.2023 21:09

can usestate do this?

Ответить
@vanchungle5504
@vanchungle5504 - 26.03.2023 06:48

Great video tutorials!

Ответить
@ismailenegadi2506
@ismailenegadi2506 - 26.03.2023 05:54

thank you for this beautiful content

😍😍😍

Ответить
@vaibhavjaiswal1309
@vaibhavjaiswal1309 - 25.03.2023 18:03

how to call a callback function in a react function bases components

Ответить
@shoumikrouf7952
@shoumikrouf7952 - 20.03.2023 08:04

cool tutorials bro

Ответить
@littlewonder8641
@littlewonder8641 - 01.02.2023 06:52

Your teaching style is fantastic and awesome. My standing ovation for this course.

Ответить
@zakariyyamaqsood7662
@zakariyyamaqsood7662 - 29.01.2023 17:21

This series is a true gem! I've been watching it in January 2023, even after 4 years, it still holds up. I commend the effort and dedication you put into making these videos. Keep up the fantastic work!

Ответить
@Basic_Info97
@Basic_Info97 - 04.01.2023 10:16

HI im just now learning react ,i tried this out in my local ,
this.state.count = this.state.count + 1;
console.log(this.state.count);
this.setState({});
i was just trying to understand the concept so i was playing with those code , at finally i ended up with this code that i have pasted up,This code gives me the proper render in page and also in console, in page its incrementing from 0 to 1 and so on , and in console the incrementing values were printing up but not the initial value 0 but 1,2,3,...in console. can anyone of here explain me wt is happening in this bit of code

Ответить
@CGN_OFFICIAL
@CGN_OFFICIAL - 29.12.2022 15:39

Hi sir, when I open my App.js file I am getting a different file instead what u r getting. Need assistance please

Ответить
@kavyasunil5715
@kavyasunil5715 - 15.12.2022 11:01

How to add image in setState on click

Ответить
@piyushdasila6129
@piyushdasila6129 - 08.12.2022 22:21

my second comment on this video and man is this series awesome!!!!!

Ответить
@AdityaSingh-ql9ke
@AdityaSingh-ql9ke - 25.11.2022 19:17

Suggestion : teaching the wrong way and then the right way makes things very messy in the viewer's mind.
You should have taught the correct way first, and then optionally taught us why other ways woudn't work.
doing so, the correct way is retained in the mind.

Ответить
@Zen-lz1hc
@Zen-lz1hc - 04.11.2022 15:20

To any newb that does not know what an arrow function is:
- Don't learn React if you don't know what an arrow function is.
- Just don't.

Ответить
@Seaspray127
@Seaspray127 - 25.10.2022 23:31

You are a good instructor. A lot of these tutorials give the imporession they are just an experienced programmer showing off. You break down the steps to the level of a beginner React student who doesn't tune into the gobblede goop technical explanations that would make sense to an advanced programmer looking at a single function. Thank you for making this course.

Ответить
@salehahmed5826
@salehahmed5826 - 15.10.2022 18:09

I am pleased

Ответить
@jokeropbro9867
@jokeropbro9867 - 19.09.2022 13:29

Thankyou Great Course

Ответить
@pampabanerjee8754
@pampabanerjee8754 - 16.09.2022 04:15

Your explaination is awesome.Helping me lot to understand react concept.

Ответить
@iuriirudov9276
@iuriirudov9276 - 10.09.2022 03:46

I hope there is an example of something similar, but the button and the counter could be in different parts of the app like two siblings.

Ответить
@mishenthakshana3407
@mishenthakshana3407 - 02.09.2022 10:23

Thanks

Ответить
@181_mdkalim7
@181_mdkalim7 - 06.08.2022 19:50

Instead of like this we can directly pass props to jsx function--
// import React from "react";

import React, { Component } from 'react'

 class Increment extends Component {

  constructor(props) {
    super(props)
 
    this.state = {
       count:0
    }
  }
 
  incre(count){
    this.setState({
      count:count+1
    })
  }
   decre(count){
    this.setState({
      count:count-1
    })
    console.log(count)
    console.log(this.state.count)
  }


  render() {
    return (
      <div>
        <h3>count : {this.state.count}</h3>
        <button onClick={()=>this.incre(this.state.count)}>Increment</button>
        <button onClick={()=>this.decre(this.state.count)}>Decrement</button>
      </div>
    )
  }
}
export default Increment

Ответить
@Ramboo339
@Ramboo339 - 30.07.2022 22:03

In the setState method, when I add the counter like - counter: (this.state.counter += 1), I get no issues as he explained in the video. How comes when I add the counter like - counter: (this.state.counter + 1) I get the count issues?

Ответить
@amitgiri6895
@amitgiri6895 - 21.07.2022 09:27

loved the content and the way you explained with do's and dont's❤❤👏👏👏👏

Ответить
@drishtisaraf8357
@drishtisaraf8357 - 20.07.2022 14:08

I have used console.log(this.state.count) but still nothing is displayed on the console.
import React, { Component } from 'react'

class Counter extends Component {

constructor(props) {
super(props)

this.state = {
count : 0

}
}

increment(){
this.state.count = this.state.count + 1
console.log(this.state.count)
}

render() {
return (
<div>
<div>
Count - {this.state.count}
</div>
<button onClick = {() => this}>Increment</button>

</div>
)
}
}

export default Counter

Ответить
@yuliasilber2123
@yuliasilber2123 - 16.06.2022 09:24

Super! Thanks 😊

Ответить
@vigneshgunasekaran2545
@vigneshgunasekaran2545 - 09.06.2022 07:21

man u r a legend!
u r saying the method prototype structure clearly. setState (object, callback). has disadvantage, so we will use setState(function, callback). Wow and you clearly explained console logs wont be in sync, unless kept in callback (which took me a day to find, luckily reached ur utube video).
1. only 1 big 'div tag in render
2. setState({count: this.state.count+1}) - updates value on screen.
this.state = this.state – wont work. – modifying the state directly
3. Calls to setState are asynchrous
ie; but console old value - to make it in sync - use in callback func of setState.
ie; entire usage of that variable in that file must be inside setState method so that it gets updated value…
4. whenever gonna access prev value of a state and gonna update, always pass a "function with prevState" as 1st parameter, instead of an "object" - like an increment
If this method called many times, still value will be increased only once. For this not happen, need to pass previous state as a parameter and in a function. (4th point)

Ответить
@sushantmore6492
@sushantmore6492 - 27.05.2022 18:47

I still didnt get the last example like why the this.state.count + 1 is giving 1 in the browser. Like whats the reason for it not updating the count value. Now when we call this.incrementFive() five times then each call will update the count like 0+1, 1+1, till 5. Or is it different. Please help

Ответить
@prakashmohaldar9004
@prakashmohaldar9004 - 25.05.2022 21:08

why is this.increament() used inside onlick function?
Cant we just write increament() inside onclick ?

Ответить
@dilshanliyanage
@dilshanliyanage - 01.05.2022 22:18

While the explanation is very clear I don't see a reason why React has made it so complicated to perform a simple operation. I think it is the frameworks/ libraries job to know how to optimize the code written by the developers while the developers should think on how to deliver the real business value. Just compare what he does with this angular code and see how simple it is. Also no need to keep in mind all these problems with async code and all that.

import { Component } from '@angular/core';

@Component({
selector: 'app-root',
template: `
<div>
<div>Count - {{count}}</div>
<button (click)="incrementFive()">Increment</button>
</div>`
})
export class AppComponent {
count = 0;

increment() {
this.count++;
}

incrementFive() {
this.increment();
this.increment();
this.increment();
this.increment();
this.increment();
}
}

Ответить
@pratikgaikwad688
@pratikgaikwad688 - 17.04.2022 15:29

Hi guys,
even I was confused about the prevState but since he spoke about passing function as args I tried below and it works:
prevState() { //function to return currentState value
return this.state.count;
}

increment() {
this.setState(prevState => ({ //use abv function to get current value
count: prevState.count + 1}))
console.log(this.state.count)
}

Hope this helps and I'm a beginner too so feel free to correct me if any mistake

Ответить
@OrincyWhyteDesigns
@OrincyWhyteDesigns - 14.04.2022 16:36

I def have to rewatch this one

Ответить
@aniruddhasengupta5718
@aniruddhasengupta5718 - 07.04.2022 07:05

setState &
prevState function

Ответить
@rogerchavez8493
@rogerchavez8493 - 18.03.2022 23:58

How does it know what prevState is? is it built in React??

Ответить
@nvHumanist
@nvHumanist - 18.03.2022 23:02

This is the kind of tutorial, I was looking for. Its a great place to learn new languages. Thanks a lot Vishwas!

Ответить