This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
export const useDebouncedState = <T>(initialValue: T, delay: number) => { | |
const [value, setValue] = useState(initialValue); | |
const [debouncedValue, setDebouncedValue] = useState(value); | |
useEffect(() => { | |
const handler = setTimeout(() => { | |
setDebouncedValue(value); | |
}, delay); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// replace occurences of :vars in the string. | |
// "This :thing is great!".format | |
String.prototype.format = function(replacements) { | |
var str = this; | |
for (var key in replacements) { | |
if (replacements.hasOwnProperty(key)) { | |
str = str.replace(':' + key, replacements[key]); | |
} | |
} |