Removed duplicated code by creating a helper function

This commit is contained in:
Alejandro Celaya
2018-08-27 16:45:22 +02:00
parent 8534c4b7bd
commit 34c5a0ef8f
4 changed files with 20 additions and 25 deletions

6
src/utils/utils.js Normal file
View File

@@ -0,0 +1,6 @@
const DEFAULT_TIMEOUT_DELAY = 2000;
export const stateFlagTimeout = (setState, flagName, initialValue = true, delay = DEFAULT_TIMEOUT_DELAY) => {
setState({ [flagName]: initialValue });
setTimeout(() => setState({ [flagName]: !initialValue }), delay);
};