Skip to content

Instantly share code, notes, and snippets.

@shiburagi
Last active September 26, 2022 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiburagi/d9b1323520c72c0784ddf1791e677c16 to your computer and use it in GitHub Desktop.
Save shiburagi/d9b1323520c72c0784ddf1791e677c16 to your computer and use it in GitHub Desktop.
const useVoucherParameter = (key) => {
const [params, setParams] = useState({})
const findRef = useRef();
useLayoutEffect(() => {
VoucherApi.initParameter().then({
complete: (res, e) => {
if (res.data) {
const params = res.data
// params.MinAmount = 600
setParams(params);
findRef.current = (parameterKey, findId) => {
return res.data[parameterKey]?.find(({ Id }) => Id === findId)
}
}
}
})
}, [key]);
return [params, findRef.current]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment