chore: add pretty

This commit is contained in:
lencx
2023-01-22 18:18:36 +08:00
parent 1ba356a91f
commit bc39dcdd72
56 changed files with 776 additions and 535 deletions

10
src/hooks/useData.ts vendored
View File

@@ -8,7 +8,7 @@ export default function useData(oData: any[]) {
useEffect(() => {
opInit(oData);
}, [])
}, []);
const opAdd = (val: any) => {
const v = [val, ...opData];
@@ -18,19 +18,19 @@ export default function useData(oData: any[]) {
const opInit = (val: any[] = []) => {
if (!val || !Array.isArray(val)) return;
const nData = val.map(i => ({ [safeKey]: v4(), ...i }));
const nData = val.map((i) => ({ [safeKey]: v4(), ...i }));
setData(nData);
};
const opRemove = (id: string) => {
const nData = opData.filter(i => i[safeKey] !== id);
const nData = opData.filter((i) => i[safeKey] !== id);
setData(nData);
return nData;
};
const opReplace = (id: string, data: any) => {
const nData = [...opData];
const idx = opData.findIndex(v => v[safeKey] === id);
const idx = opData.findIndex((v) => v[safeKey] === id);
nData[idx] = data;
setData(nData);
return nData;
@@ -52,4 +52,4 @@ export default function useData(oData: any[]) {
};
return { opSafeKey: safeKey, opInit, opReplace, opAdd, opRemove, opData, opReplaceItems };
}
}