Common issue with synchronizing state in React

Поделиться
HTML-код
  • Опубликовано: 30 дек 2019
  • I often see new React developers struggle with this issue: "How do I synchronize two states when one depends on the other?"
    In this video we walk through a code example, the way many new developers approach it, and finally end up with a working and clean solution.
    The code progression can be seen in these three codesandboxes:
    codesandbox.io/s/setting-stat...
    codesandbox.io/s/usestate-use...
    codesandbox.io/s/derive-value...
    Follow me! / brookslybrand

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

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

    dude thank you so much for this tutorial! I couldn't get my head around how this was supposed to work but the way you explained it made me get it instantly!

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

    Thanks , nice explanation!!

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

    You may use e.target.value directly, anything that is not reactive, i.e input that changes only by user activity, should not be a state at all.. still if you need it... rather use a ref in that case

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

      Yep, in a lot of situations you're absolutely right! I was just trying to demonstrate a pattern a lot of developers do (trying to synchronize two states), and a method I prefer (deriving a value from the state)