Fix items are not updated when using mass editor

pull/1527/head
LASER-Yi 3 years ago
parent ccd5473598
commit 60e2732f48

@ -6,7 +6,6 @@ import React, {
MouseEvent, MouseEvent,
PropsWithChildren, PropsWithChildren,
useCallback, useCallback,
useRef,
useState, useState,
} from "react"; } from "react";
import { Button } from "react-bootstrap"; import { Button } from "react-bootstrap";
@ -59,16 +58,13 @@ export function ContentHeaderAsyncButton<T extends () => Promise<any>>(
const [updating, setUpdate] = useState(false); const [updating, setUpdate] = useState(false);
const promiseRef = useRef(promise);
const successRef = useRef(onSuccess);
const click = useCallback(() => { const click = useCallback(() => {
setUpdate(true); setUpdate(true);
promiseRef.current().then((val) => { promise().then((val) => {
setUpdate(false); setUpdate(false);
successRef.current && successRef.current(val); onSuccess && onSuccess(val);
}); });
}, [successRef, promiseRef]); }, [onSuccess, promise]);
return ( return (
<ContentHeaderButton <ContentHeaderButton

@ -26,17 +26,15 @@ export const Chips: FunctionComponent<ChipsProps> = ({
const input = useRef<HTMLInputElement>(null); const input = useRef<HTMLInputElement>(null);
const changeRef = useRef(onChange);
const addChip = useCallback( const addChip = useCallback(
(value: string) => { (value: string) => {
setChips((cp) => { setChips((cp) => {
const newChips = [...cp, value]; const newChips = [...cp, value];
changeRef.current && changeRef.current(newChips); onChange && onChange(newChips);
return newChips; return newChips;
}); });
}, },
[changeRef] [onChange]
); );
const removeChip = useCallback( const removeChip = useCallback(
@ -46,14 +44,14 @@ export const Chips: FunctionComponent<ChipsProps> = ({
if (index !== -1) { if (index !== -1) {
const newChips = [...cp]; const newChips = [...cp];
newChips.splice(index, 1); newChips.splice(index, 1);
changeRef.current && changeRef.current(newChips); onChange && onChange(newChips);
return newChips; return newChips;
} else { } else {
return cp; return cp;
} }
}); });
}, },
[changeRef] [onChange]
); );
const clearInput = useCallback(() => { const clearInput = useCallback(() => {

Loading…
Cancel
Save