save-on-navigate-back
A common pattern in native apps is to automatically save state when navigating away from detail
pages. This component and hook provide an easy way to hook into react-navigation's onBeforeRemove
event to run your Formik onSubmit function before navigation.pop
#
Installation#
API#
SaveOnNavigateBackRender this component when you want to intercept back navigation and run your save function.
Conditionally rendering this on a page makes it easy to control when your save function will fire.
Eg, only autosave after the object has been created explicitly by the user.
This component needs a React.ref wrapped boolean value in order to work. We provide a helper for
this with useSaveOnNavigateBack
#
useSaveOnNavigateBackRef and component wrapped as hook, for easier consumption. Returns the SaveOnNavigateBack component, the boolean ref (to be passed into the SaveOnNavigateBack component), and a helper fn to set formSuccess value.