javascript - Application vs. local state in redux -


in many redux examples, some_async_action_error or some_async_pending actions dispatched manipulate global state. can't think of scenario make sense component rendered global error / loading / pending state. when component destroyed , remounted, async error need "cleared", making seem manipulating component's local state better choice.

considering this, what's best practice dealing loading / error / pending states in redux:

  • should component default initial state locally still subscribe global application state loading / errors?
  • or should application state error / loading reset after leaving component?
  • or should these transitory states managed locally?

from understanding, best practice in redux store application in global store, have individual components subscribe relevant information store, using connect(mapstatetoprops)(component). rather having global application loading property, individual components subscribe relevant flag, such users.loading

see http://rackt.org/redux/docs/basics/usagewithreact.html more

edit: further answer question, each action should clean after itself, dispatching action. might have request_user adds loading flag , resets error state, followed receive_user, removes loading flag, or failed_to_recieve_user, removes loading flag, buts adds error state. pattern described pretty thoroughly here: https://github.com/agraboso/redux-api-middleware#redux-standard-api-calling-actions


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -