React js Tutorial - Save Data In Your Application With localStorage and sessionStorage

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024
  • React JS - The Complete Guide (over 150 000 developers have taken this course):
    bit.ly/2oCrfH0
    Featured Full Courses:
    React JS - The Complete Guide (over 150 000 devs enrolled)
    bit.ly/2oCrfH0
    React JS Web Development - The Essentials Bootcamp
    bit.ly/2oEK2S1
    The Complete React Js & Redux Course - Build Modern Web Apps
    bit.ly/2mWNebj
    The Complete React Native + Hooks Course
    bit.ly/2mofraC
    React Native - The Practical Guide
    bit.ly/2nTm98O
    The Complete JavaScript Course 2019
    bit.ly/2mjsbiB
    Learn how to save data in your React application by using localStorage and sessionStorage.

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

  • @mohamedhemidi
    @mohamedhemidi 3 года назад +3

    Short and straight to the point , thank you Bro !

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

    short and powerful videos haha thanks man you helped me alot..

  • @Eminence43rd
    @Eminence43rd 4 года назад +9

    Where is your microphone positioned while doing this video, my earphones so weird.

  • @danilsviridenko6565
    @danilsviridenko6565 4 года назад +3

    if somebody want to see normal React (Local Storage)code which was writte with using Functional components here he is:
    function App () {
    const [state,setState] = React.useState({
    user: '',
    rememberMe: false
    })
    const ref = useRef(null)
    const handleChange = (event) => {
    const input = @t;
    const value = input.type === 'checkbox' ? input.checked : input.value;
    setState(Object.assign({}, state, {[input.name]: value }));
    };
    localStorage.setItem('foo', 'foo')
    const handleFormSubmit = () => {
    const { user, rememberMe } = state;
    localStorage.setItem('rememberMe', JSON.stringify(rememberMe));
    if (rememberMe) {
    localStorage.setItem('user', JSON.stringify(user));
    } else {
    localStorage.setItem('user', '');
    }
    };
    useEffect( () => {
    const rememberMe = localStorage.getItem('rememberMe') === 'true';
    const user = rememberMe ? JSON.parse(localStorage.getItem('user')) : '';
    setState({ user, rememberMe });
    },[])
    return (
    User:
    Remember me
    Sign In
    );
    }

  • @user-yv7hk7tg2f
    @user-yv7hk7tg2f 2 года назад +1

    Why does the sound only come from the left...

  • @luccassodre4078
    @luccassodre4078 4 года назад +1

    Great explanation. Thanks

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

    Thank you for the video. Could you access the set data from windows explorer for example?

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

    woww... brother.. that's cool

  • @A8Sea
    @A8Sea 4 года назад +1

    Well made video, Thanks so much.

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

    Once I have this code working, how can I use the value from an input field to save into localStorage? Sorry, I'm still learning.

  • @albertvaldes2580
    @albertvaldes2580 4 года назад +1

    Great, thanks for the video

  • @robertoaleydon3044
    @robertoaleydon3044 4 года назад +1

    Very good, thanks for this tutorial

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

    What if user data is sensitive and you still need to store in UI what we can use apart from local storage????

  • @youssef.elmoumen
    @youssef.elmoumen 3 года назад

    Thanks for the tutorial but i have a big problem with that localstorage when I'm trying to save JWT.. even when I put in a Promise the first time it returns undefined

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

    Your audio is only on the left side fyi

  • @catapult171
    @catapult171 4 года назад +1

    Nicely explained and very helpful. Thank you.

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

    are local and session storage limited to class based components? How would implement them using functional components

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

      It shd work on functional components i guess.

  • @mr.RAND5584
    @mr.RAND5584 Год назад

    Why class?

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

    How it's working dynamically like when user came on the page get user data in local storage?

    • @300deQI
      @300deQI 3 года назад

      UseEffect

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

    do it with a useState

  • @SapanKumarDas
    @SapanKumarDas 5 лет назад

    Boss, what are the difference?

    • @FullstackDevelopment
      @FullstackDevelopment  5 лет назад +1

      It's mentioned at 5:09. With localStorage the data persists if the user closes the browser, with sessionStorage the data is only accesible for the current session.

  • @ProgrammingwithPeter
    @ProgrammingwithPeter 5 лет назад

    localstorage api is unrelated to any frameworks, it's language specs

    • @FullstackDevelopment
      @FullstackDevelopment  5 лет назад

      Yes it was introduced in HTML5 and works in most web clients with regular js, this is an example of how to use it in react js.

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

    Bhaiya Thora voice tez kr lo ... .

  • @imtiazkabir6115
    @imtiazkabir6115 4 года назад +1

    Totally incomplete, do you ever refresh your page? You will lost everything.

    • @shubh_1999
      @shubh_1999 4 года назад +3

      No, its the console logs which are being flushed. If you go to the application tab in the developer console, you'll see the key value pair. Infact, in localstorage, even if you restart your PC, you shall still see the data.

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

    Speak up or invest in a better microphone.