mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-15 17:43:08 -04:00
New plugin: VoiceMessages (#1380)
Co-authored-by: V <vendicated@riseup.net> Co-authored-by: Justice Almanzar <superdash993@gmail.com>
This commit is contained in:
parent
198b35ffdc
commit
8620a1d86d
16 changed files with 660 additions and 37 deletions
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { React, useEffect, useReducer, useState } from "@webpack/common";
|
||||
import { React, useEffect, useMemo, useReducer, useState } from "@webpack/common";
|
||||
|
||||
import { makeLazy } from "./lazy";
|
||||
import { checkIntersecting } from "./misc";
|
||||
|
@ -135,3 +135,24 @@ export function LazyComponent<T extends object = any>(factory: () => React.Compo
|
|||
return <Component {...props} />;
|
||||
};
|
||||
}
|
||||
|
||||
interface TimerOpts {
|
||||
interval?: number;
|
||||
deps?: unknown[];
|
||||
}
|
||||
|
||||
export function useTimer({ interval = 1000, deps = [] }: TimerOpts) {
|
||||
const [time, setTime] = useState(0);
|
||||
const start = useMemo(() => Date.now(), deps);
|
||||
|
||||
useEffect(() => {
|
||||
const intervalId = setInterval(() => setTime(Date.now() - start), interval);
|
||||
|
||||
return () => {
|
||||
setTime(0);
|
||||
clearInterval(intervalId);
|
||||
};
|
||||
}, deps);
|
||||
|
||||
return time;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue