Improve types (#11239)

This commit is contained in:
Michael Telatynski 2023-07-12 15:56:51 +01:00 committed by GitHub
parent 44615b2b04
commit f1534fda79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 42 deletions

View file

@ -16,13 +16,13 @@ limitations under the License.
import { useState } from "react";
export const useLocalEcho = <T>(
export const useLocalEcho = <T, V extends T = T>(
currentFactory: () => T,
setterFn: (value: T) => Promise<unknown>,
setterFn: (value: V) => Promise<unknown>,
errorFn: (error: unknown) => void,
): [value: T, handler: (value: T) => void] => {
): [value: T, handler: (value: V) => void] => {
const [value, setValue] = useState(currentFactory);
const handler = async (value: T): Promise<void> => {
const handler = async (value: V): Promise<void> => {
setValue(value);
try {
await setterFn(value);