-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add connect wallet analytics event (#231)
- Loading branch information
1 parent
ff046b6
commit a50e953
Showing
4 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { useEffect, useRef } from "react"; | ||
import { useState } from "react"; | ||
|
||
export const usePrevious = (value: any) => { | ||
const ref = useRef(); | ||
useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref.current; | ||
const [current, setCurrent] = useState(value); | ||
const [previous, setPrevious] = useState(null); | ||
|
||
if (value !== current) { | ||
setPrevious(current); | ||
setCurrent(value); | ||
} | ||
|
||
return previous; | ||
}; | ||
|
||
export default usePrevious; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useState } from "react"; | ||
|
||
export const useValueHistory = <T>( | ||
value: T, | ||
limit: number, | ||
): [T, ...Array<T | undefined>] => { | ||
const [values, setValues] = useState([ | ||
value, | ||
...Array(limit - 1).map((v) => undefined), | ||
]); | ||
const current = values[0]; | ||
|
||
if (value !== current) { | ||
setValues([value, ...values.slice(0, -1)]); | ||
} | ||
|
||
return values as [T, ...Array<T | undefined>]; | ||
}; | ||
|
||
export default useValueHistory; |
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
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