File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,26 @@ export const useLoadingEffect = (
58
58
useEffect ( effect , [ useContext ( VersionContext ) , ...deps ] ) ;
59
59
} ;
60
60
61
+ /**
62
+ * a hook that runs an effect when the version changes, which is incremented on each route change or reload.
63
+ * and skips the first run.
64
+ * @param effect the effect to run
65
+ * @param deps the dependencies
66
+ */
67
+ export const useReloadEffect = (
68
+ effect : React . EffectCallback ,
69
+ deps : React . DependencyList = [ ]
70
+ ) => {
71
+ const [ once , setOnce ] = useState ( true ) ;
72
+ useEffect ( ( ) => {
73
+ if ( once ) {
74
+ setOnce ( false ) ;
75
+ return ;
76
+ }
77
+ return effect ( ) ;
78
+ } , [ useContext ( VersionContext ) , ...deps ] ) ;
79
+ } ;
80
+
61
81
/**
62
82
* a context that can be used to reload the current page
63
83
*/
You can’t perform that action at this time.
0 commit comments