Conform more of the codebase to strict types (#11191)

This commit is contained in:
Michael Telatynski 2023-07-05 11:53:22 +01:00 committed by GitHub
parent 4044c2aa66
commit 8107f1d271
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 88 additions and 57 deletions

View file

@ -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);