0

Application data lives in stores
Application (ui) state lives in stores (there are different opinions tho)

When the user now submits a form and the server returns a validation error, hot do I get this error back to the view component (the form)? Since the (controller) view components only gets updated by change events from the store(s), the error would need to be added to a store. Other people say that in those cases the view components should be able to listen to events from the action creators.

Whats your opinion on that?

Aron Woost
  • 19,268
  • 13
  • 43
  • 51

1 Answers1

1

Possibly a duplicate of How to handle async errors in Flux?

In the case where the error doesn't really matter to the rest of the app and you don't need to log it, I'd just return the value right to the component. For example, say you're submitting a form and it comes back 422 or something...unless you want to do something with the error like store it, and none of the other components really care that it errors, don't worry about it...just update the state of the View Component.

Although generally speaking it's best to have state at the top most component, it makes sense for some components (like forms) to have a "transient" state that only matters to them...for example when you're typing in text to a box there's no reason to bubble that up to the top-level component usually.

Community
  • 1
  • 1
SleepyProgrammer
  • 443
  • 1
  • 5
  • 15
  • How should the action "return to the component"? The action does not know about the component... – Aron Woost Apr 14 '15 at 13:18
  • 1
    Jing Chen comments here on how to do it through the store: https://groups.google.com/forum/#!topic/reactjs/yAefvkC62Ts For my case, I actually just sent the data + a promise to my API Action creator via the submit method of my form, and then had some code execute to set the local state when the "outer promise" is resolved by the API call. – SleepyProgrammer Apr 14 '15 at 13:26