1

First, thank you for your patience and expertise. Without you, I'd be mopping floors. From Linus Torvalds to DHH to you-- Awesome.

So I have a question duplicate ( answered here-- Why calling setState method doesn't mutate the state immediately? )

I have a 42 radio group form that calls setState for each choice. The above solution says the calls are asynchronous and cause the components to reload. I don't [think I] need to do that. How would you store in memory-- session, cookie -- or something that doesn't cause a repaint until the user submits the form? Sorry if this is another duplicate. I'm slow that way.

Again, thanks.

Anas
  • 5,622
  • 5
  • 39
  • 71
listenlight
  • 654
  • 1
  • 12
  • 27

1 Answers1

2

Not "repainting" the page is not how react works. I am constantly "repainting" the screen as the user interacts with the page I work on.

You want to use setState because if the user keeps clicking around you want to be able to keep updating and tracking what they did, so each update doesn't overwrite. The asynchronous update is beneficial in that you get a copy of the state at the exact moment the user fired off the actions, which ensures you don't end up in a funky state if a user updates a few things at once.

This might be an "asynchronous" update but it feels like it happens immediately and triggers the components to update themselves with the new information (aka repainting)

Tall Paul
  • 2,398
  • 3
  • 28
  • 34
  • 1
    Oh boy, I lapsed mentally and couldn't see that the state was there as it should be, also forgot to count my zero element. Long day. – listenlight Aug 21 '18 at 18:48
  • 1
    all good, glad I could help @tidelake. The other thing I suggest is looking at possible state management solutions like redux. I personally really like them as it makes it easy to manage exactly how my data flows and allows me to easily pass data around. – Tall Paul Aug 21 '18 at 19:03