React tutorial in Hindi #12 State with class component

Поделиться
HTML-код
  • Опубликовано: 9 сен 2024
  • in this react js tutorial for beginners series we learn how to use state in a class component in react js. This video is made by anil Sidhu in the Hindi Language.
    Playlist for complete React series in Hindi
    link • React tutorial for beg...
    git github.com/ani...
    State in Class Component
    Make Class Component
    What is state
    Define state
    Update state with a Button click
    Interview Question
    Join on Insta @php.step.by.step

Комментарии • 55

  • @kirtisoni21
    @kirtisoni21 11 месяцев назад +3

    Thanks a lot sir, I have learned many things.

  • @fatemapatel9122
    @fatemapatel9122 3 года назад +15

    No, we can't use useState in class-component because, useState is a Hook and Hooks are not implement in class-component.

  • @subhendu2134
    @subhendu2134 Месяц назад

    In React, state is not public, state is private to the component in which it is defined. This means that the state is not accessible or modifiable by other components directly.

  • @khyzersaleem
    @khyzersaleem 3 месяца назад

    React Class Components have built in State Object. You might have noticed that we used state earlier in the component constructor section. The state object is where you store property values that belongs to the component. When the state object changes, the component re-render.
    ONLY call useState() hooks inside a functional component: Hooks are created for functional components and should only be used in functional components. They don't work in class components. If you need to use state in the class component, then use the state object.

  • @harmankaur3359
    @harmankaur3359 Год назад +3

    clearly explained!

  • @nabilalakhani4182
    @nabilalakhani4182 3 года назад +1

    ur videos are ultimate keep up the good work thanks

  • @fea25akshaygirase79
    @fea25akshaygirase79 Год назад +1

    op lecture sir

  • @ricky_una_16
    @ricky_una_16 Год назад +1

    Sir I have a small doubt regarding state, apne bola state public hai but google mai private show kr raha hai. So which one is correct, please clear it.
    Anyone also can verify me about this doubt.

    • @mohitpipaliya2594
      @mohitpipaliya2594 Год назад +2

      In React, state can be either public or private.
      Public State: Public state refers to the state that is accessible and modifiable from outside the component. It's typically used when the state needs to be shared across multiple components or when you want to update the state from a parent component. Public state is managed using the props system, where a parent component passes down state as props to its child components. This makes the state public and accessible to those child components.
      Private State: Private state refers to the state that is local and specific to a component. It's not directly accessible or modifiable from outside the component. Private state is managed using the useState or other state management tools within the component. It's used when you want to keep the state isolated to a specific component and avoid unintended interactions with other components.
      let me know if you still don't understand, I'll give you code example for better understanding

  • @navjyotyadav4053
    @navjyotyadav4053 5 месяцев назад

    Is state public or private? you said, its public then we should be able to use it outside of component. And also you said, state can not be used outside the component. These two statements conflicts each other.
    I think state in react is private, not public. what do you think? Please reply here.

    • @kevalhirpara6747
      @kevalhirpara6747 4 месяца назад

      bhai google me state private dikha rahi he

  • @prosinging7853
    @prosinging7853 2 года назад +1

    this.setState is onestep behind. tried with await in SetState but that also not working. what might be wrong.When I am testing api with postman .Getting proper result but at the time of SetState it is one step behind when I console warn after assigning state

    • @khyzersaleem
      @khyzersaleem 3 месяца назад

      Use Arrow Function In OnClick Then Use this.setState

  • @nikhilgaming4147
    @nikhilgaming4147 2 года назад +2

    No,we can't use hooks inside the class component

  • @saurabhmore5164
    @saurabhmore5164 3 года назад +2

    Can we only define the state without giving any value or data?

  • @shoaib4x533
    @shoaib4x533 Год назад

    Maza aagya sir 🔥🔥

  • @harshitrathi3077
    @harshitrathi3077 3 года назад +1

    Thankyou Bro

  • @sachindandge764
    @sachindandge764 2 года назад +1

    Hello sir i have been watching your this series but it seems to me difficult as I am a beginner.plz make a videos of react which will have small code snippets as an examples to understand it better..

    • @frontendwale
      @frontendwale Год назад

      Hi Sachin, you may try to look on this ruclips.net/channel/UCjL4SPbBlJoOKT_YZz6zISQ

    • @tanmayhedau5342
      @tanmayhedau5342 Год назад +1

      u should have basic knowledge of html n css that's it and javascript too

  • @himanshuchauhan6520
    @himanshuchauhan6520 3 года назад

    if i am using 2 this.state in the constructor() like this
    constructor()
    {
    super();
    this.state={data:"Himanshu"}
    this.state={number:1}
    }
    but i am not getting any output on the browser until i click the button
    return (

    {this.state.data}
    {this.state.number}
    this.Inc()}>Surname

    );
    Can you tell me why ?

    • @ChandanSingh-ww5hr
      @ChandanSingh-ww5hr Год назад +2

      @himanshuchauhan6520 bro you don't need to create a separate state just put all the state data together like this
      super();
      this.state={data:"Himanshusu", number:1}
      this will work

    • @ashurajput357
      @ashurajput357 Год назад

      ​@@ChandanSingh-ww5hr yes because mentioning this.state two times is wrong because now they are now different objects.

  • @WebDeveloper831
    @WebDeveloper831 6 месяцев назад

    Sir apne bola he ke state public hote hy lekin chatgpt to private btaa rhee he ap ye confirm kar den...

  • @apkaChotaBhai
    @apkaChotaBhai 3 года назад

    Bhai very gud yaar, thanks bade bhai
    Bss insta pe msg ka reply kar diya karo, and video me 5-7 min leke css ko bhi re-render karke dikha diya karo bhai

  • @Radhashreeradha
    @Radhashreeradha 3 года назад

    Sir why we are not use function keyword in that case

  • @ZahidKhan-th8pz
    @ZahidKhan-th8pz 3 года назад

    Sir state private hoti h na usko as a argument use krte h hm log dusre components me

    • @tejasdeore8340
      @tejasdeore8340 2 года назад

      No state public hoti h previous video me bataya h

  • @DeepakGupta-hj2dv
    @DeepakGupta-hj2dv 3 года назад +1

    Redux ke video kab aayege?

  • @abhisheksinghtomar159
    @abhisheksinghtomar159 3 года назад

    Why we can't use this.apple here?

  • @sanketdeogade4490
    @sanketdeogade4490 2 года назад

    How to update state immediately using class component?
    Because whenever I try to do setState, it doesn't update immediately.
    We can use useEffect in functional components
    But what about class components?
    How can we do it?

    • @aashitkumarsinha3459
      @aashitkumarsinha3459 2 года назад

      use componentDidMount life cycle

    • @sanketdeogade
      @sanketdeogade 2 года назад

      @@aashitkumarsinha3459 How to make it work for last update of setState?

    • @aashitkumarsinha3459
      @aashitkumarsinha3459 2 года назад

      @@sanketdeogade it get automatically render at time of states get loaded first time, but it also get called by React...when the state gets changes...

  • @shaheenkhan6313
    @shaheenkhan6313 3 года назад +1

    I think no we cannot use useState in class component because it gives error

    • @codestepbystep
      @codestepbystep  3 года назад

      Right

    • @ayaankh245
      @ayaankh245 3 года назад

      because it is hook. Hooks are for function components only.

  • @riteshgoswami1596
    @riteshgoswami1596 3 года назад

    hook in only for function component

  • @shubhamkurulekar4551
    @shubhamkurulekar4551 2 года назад

    states are public ?is it right?i think private is right

    • @tejasdeore8340
      @tejasdeore8340 2 года назад

      He mentioned in his previous video that state is public

    • @nileshgore4790
      @nileshgore4790 Год назад +1

      yes bro I also think state is private

  • @syedateeq1602
    @syedateeq1602 3 года назад +2

    we can use it
    example.
    const [state, setState] = useState({
    count: 0
    });
    console.log(state.count);
    and update it like this
    setState({ count: state.count + 1 });

  • @user-rj7tr5rl8c
    @user-rj7tr5rl8c 4 месяца назад

    itna bareek kar rakha text dikh bhi ni raha

  • @roshanpandey4041
    @roshanpandey4041 Год назад

    how state is public ?

  • @GautamKumar_39
    @GautamKumar_39 Год назад

    STATE IS PRIVATE, NOT PUBLIC

  • @anupriya4113
    @anupriya4113 Год назад

    state is private not public

  • @riderzzone6373
    @riderzzone6373 Год назад

    laptop me charge bhi diya karo sir 🤣🤣

  • @coder-cc4pd
    @coder-cc4pd 5 месяцев назад

    ONLY call useState() hooks inside a functional component: Hooks are created for functional components and should only be used in functional components. They don't work in class components

  • @jawadullah4685
    @jawadullah4685 2 года назад

    No Nahe