You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to the section on Posting + Refreshing Data, I'd like to push a new browser state after an update action. In my app, there is no separate view for an "edit" action: users can click an edit button, and the row reformats to inputs. My problem lies in redirecting back to the list view after the update action completes.
I have it working with the following:
importReact,{Component}from'react';import{connect}from'react-refetch';import{authHeader}from'lib';classListextendsComponent{// ...componentWillReceiveProps(nextProps){const{fetchPref: nextFetchPref}=nextProps;const{ fetchPref }=this.props;if(fetchPref&&nextFetchPref&&fetchPref.pending&&nextFetchPref.fulfilled){this.context.router.push({pathname: '/admin/prefs'});}}// ...render(){// omitting the rest of the JSX for the sake of brevity, but this is actually// a table where each row has an edit button that invokes `patchPref`// with the `id` for the row and the `data` from user inputreturn(<aonClick={this.props.patchPref.bind(this,id,data)}>edit</a>);}}exportdefaultconnect((props)=>({fetchPrefs: {url: '/api/prefs',headers: authHeader(),},patchPref: (id,data)=>({fetchPref: {url: `/api/prefs/${id}`,method: 'PATCH',body: JSON.stringify(data),headers: authHeader(),andThen: ()=>({fetchPrefs: {url: '/api/prefs',headers: authHeader(),force: true,refreshing: true,}}),}}),}))(List);
As you can see, I've had to do some this.props/nextProps checking in componentWillReceiveProps to support the behavior I'm after.
What I'd _like_ to do is define a then clause on patchPref so that I could invoke it along the lines of:
Do all the react-refetch stuff defined in connect for patchPref, then do this other thing.
That would allow me to completely delete componentWillReceiveProps.
As the return of this.props.patchPref() is undefined, and as then: and andThen: don't have access to this.context, it doesn't seem like my desired solution is possible currently.
I don't know if such a thing would be possible, or if there is another/cleaner way of accomplishing the same behavior with the library as it is now.
Was hoping to hear y'alls thoughts on this.
The text was updated successfully, but these errors were encountered:
Related to the section on Posting + Refreshing Data, I'd like to push a new browser state after an update action. In my app, there is no separate view for an "edit" action: users can click an edit button, and the row reformats to inputs. My problem lies in redirecting back to the list view after the update action completes.
I have it working with the following:
As you can see, I've had to do some
this.props
/nextProps
checking incomponentWillReceiveProps
to support the behavior I'm after.What I'd _like_ to do is define a
then
clause onpatchPref
so that I could invoke it along the lines of:The intention being:
That would allow me to completely delete
componentWillReceiveProps
.As the return of
this.props.patchPref()
isundefined
, and asthen:
andandThen:
don't have access tothis.context
, it doesn't seem like my desired solution is possible currently.I don't know if such a thing would be possible, or if there is another/cleaner way of accomplishing the same behavior with the library as it is now.
Was hoping to hear y'alls thoughts on this.
The text was updated successfully, but these errors were encountered: