reactjs - Check is there are unsaved changes in a redux app -


i'm looking example of how check changes in react-redux application. application prompt user unsaved changes when attempting navigate away current route.

thank in advance.

doing involve in component:

onclicknavigationlink = () => {   const { checklocalstate } = this.props;   checklocalstate() // have access cause of `connect`     .then(res => {       if (res.arechanges) {         this.setstate({ proptuserconfirmation: true })       } else {         this.onclicknavigationconfirmation();       }     }) }  onclicknavigationconfirmation = () => {   const { push } = this.props;    push('/nexturl'); } 

and action like

function checklocalstate() {   return (dispatch, getstate) => {     return api.checklocalstate(getstate());   } } 

this require server-side service can diff local state , redux state tree. don't recommend general pattern begin with, however. should know in local application state if user has unsaved data.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -