Conform more of the codebase to strict types (#11191)
This commit is contained in:
parent
4044c2aa66
commit
8107f1d271
25 changed files with 88 additions and 57 deletions
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Dispatch, SetStateAction, useCallback, useEffect, useState } from "react";
|
||||
import { Dispatch, useCallback, useEffect, useState } from "react";
|
||||
|
||||
const getValue = <T>(key: string, initialValue: T): T => {
|
||||
try {
|
||||
|
@ -26,7 +26,7 @@ const getValue = <T>(key: string, initialValue: T): T => {
|
|||
};
|
||||
|
||||
// Hook behaving like useState but persisting the value to localStorage. Returns same as useState
|
||||
export const useLocalStorageState = <T>(key: string, initialValue: T): [T, Dispatch<SetStateAction<T>>] => {
|
||||
export const useLocalStorageState = <T>(key: string, initialValue: T): [T, Dispatch<T>] => {
|
||||
const lsKey = "mx_" + key;
|
||||
|
||||
const [value, setValue] = useState<T>(getValue(lsKey, initialValue));
|
||||
|
@ -35,7 +35,7 @@ export const useLocalStorageState = <T>(key: string, initialValue: T): [T, Dispa
|
|||
setValue(getValue(lsKey, initialValue));
|
||||
}, [lsKey, initialValue]);
|
||||
|
||||
const _setValue: Dispatch<SetStateAction<T>> = useCallback(
|
||||
const _setValue: Dispatch<T> = useCallback(
|
||||
(v: T) => {
|
||||
window.localStorage.setItem(lsKey, JSON.stringify(v));
|
||||
setValue(v);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue