@expandorg/app-utils
Advanced tools
Comparing version 0.0.33 to 0.0.34
@@ -19,3 +19,7 @@ // @flow | ||
import { SubmitStateEffect, submitStateEffect } from './src/submitStateEffect'; | ||
import { | ||
SubmitStateEffect, | ||
submitStateEffect, | ||
useSubmitEffect, | ||
} from './src/submitStateEffect'; | ||
@@ -28,2 +32,3 @@ export { | ||
submitStateEffect, | ||
useSubmitEffect, | ||
initialRequestState, | ||
@@ -30,0 +35,0 @@ handleAsyncCall, |
{ | ||
"name": "@expandorg/app-utils", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "App utils", | ||
@@ -18,6 +18,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"@expandorg/api-client": "^0.0.18", | ||
"@expandorg/api-client": "^0.0.19", | ||
"@expandorg/utils": "^0.0.8" | ||
}, | ||
"gitHead": "82f6802e4405e508219a27d2401ef13511f01f73" | ||
"gitHead": "3c71d394a203780ee66d002a1f9e3fb351c0d8df" | ||
} |
// @flow | ||
import { Component } from 'react'; | ||
import { Component, useEffect, useRef } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -85,1 +85,31 @@ import { connect } from 'react-redux'; | ||
}; | ||
function usePrevious(value) { | ||
const ref = useRef(); | ||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
} | ||
export function useSubmitEffect( | ||
submitState: SubmitState, | ||
complete: Function, | ||
failed: Function | ||
) { | ||
const current = submitState.state; | ||
const prev = usePrevious(current); | ||
useEffect(() => { | ||
if (prev === current) { | ||
return; | ||
} | ||
const prevFetching = prev === RequestStates.Fetching; | ||
if (prevFetching && current === RequestStates.Fetched) { | ||
complete(); | ||
} | ||
if (prevFetching && current === RequestStates.FetchError) { | ||
failed(); | ||
} | ||
}, [complete, failed, current, prev]); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17156
613
+ Added@expandorg/api-client@0.0.19(transitive)
- Removed@expandorg/api-client@0.0.18(transitive)