repo.or.cz
/
ProtonMail-WebClient.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Merge branch 'fix-typo-drive' into 'main'
[ProtonMail-WebClient.git]
/
packages
/
hooks
/
useInstance.ts
blob
a95b7f9f240b74c672d67022bd9fbfe482b6cf44
1
import { useRef } from 'react';
2
3
/**
4
* Use ref with callback support.
5
*/
6
const useInstance = <T>(fn: () => T): T => {
7
const ref = useRef<T>();
8
if (!ref.current) {
9
ref.current = fn();
10
}
11
return ref.current;
12
};
13
14
export default useInstance;