mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: add pretty
This commit is contained in:
10
src/hooks/useData.ts
vendored
10
src/hooks/useData.ts
vendored
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user