In-Place Optimistic UI

Поделиться
HTML-код
  • Опубликовано: 9 фев 2025

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

  • @luizhrocha
    @luizhrocha 10 месяцев назад +3

    I’d never find out how to fix this flicker problem without this.

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

    Lovely, I love this series of quick videos and the trick with flush is nice to know since the flick even for me is barely noticeable even if i do focus lmao

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

    I was waiting for this video all day. Thanks

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

    OMG I learn so much from this

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

    you are the chosen one. focus managment with useefect or, death, death is better

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

    It would be easier to remove button altogether and leave just text input and style it with :focus pseudo class. This would help to remove all this hacky flushSync and changing props values

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

      That's what I've done too. The tailwind pseudo classes can get pretty gnarly if the field is required, has error validation, animations, and other design requirements.

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

      @@anttihiljacan u share some code showing the gnarliness of tailwind in those situations? I’m starting a new project (remix, prisma, tailwind). So far it’s been a dream but I am starting to have some trouble with styling a component based on if the error state exists

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

    Is there a way to reset the form data from fetcher last value to null or something like that ?

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

    6:32 wait wait, props are lets?

    • @RyanFlorence
      @RyanFlorence Год назад +7

      Technically `var` but the kids don't know what that is.

  • @rafaeljdm
    @rafaeljdm Год назад +4

    Please Ryan, give us the code :p

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

    I learned to never mutate props. Is that not true? I see you mutate value during the post and revalidation.

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

      Same 😂 In that case I would use the useMemo derived from fetcher.formData.get(field) and revalidated value

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

      I am mindblown, I didn’t know it is technically a let. I would have used useState and do a whole bunch of extra code😂

    • @ReactTipsWithBrooks
      @ReactTipsWithBrooks Год назад +4

      You should never mutate a prop, meaning if something like an object is passed in you should not mutate the values in that object. The reason being a) you may know what else is relying on that prop, and b) you might not know when React is going to re-render and re-change the value of that prop
      However, what Ryan is doing here isn't mutation, he's just reassigning the prop
      let a = { key: 'this thing' }
      a = { key: 'that thing' }
      The object originally assigned to a wasn't mutated, the variable a was just reassigned a new value. All that const does is says "a can never be reassigned"
      a.key = 'new value'
      Anyway, all that to say if this makes you nervous, you can just declare a new variable
      const copyOfProp = prop
      Hope that helps!

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

      @@ReactTipsWithBrooks Amazing explanation! Always helping the community ❤

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

      To be even more clear, it's the destructuring that declares new aliases for the values.
      Consider: let {a, b} = props;
      This is essentially the same as: let a = props.a; let b = props.b;
      You are now free to reassign `a` or `b` without mutating `props`. If you would mutate the thing _inside_ of `a` or `b`, for instance by doing `a.push()` or something, then `props` will be mutated to. But reassignment just means that `a` or `b` are no longer pointing to values inside `prop`.

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

    What happens if the network request fails?

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

      It depends on what the action returns when that happens. Assuming it returns normally (i.e. some JSON) instead of throwing an error or alternative response, then the revalidation will kick in the same and reload the data from the server. The component will re-render with the old name, and the action's JSON available through the fetcher.
      If it *does* throw, then Remix will want to render an error component AFAIK.

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

    You need to handle if the request fails and go back to the initial value before the request was sent

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

      Remix will do that automatically. It'll fetch the actual data from the server wheter it changed successfully or not.

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

    About "let" and "const" typescript doesnt let me use let when I want ahhahahah

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

    So confused. What is this. What are you doing or trying to do. Literally 100% of context missing from this video. What platform? Why what who when this is so confusing.