mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-16 00:50:18 -04:00
nested useImmutable
This commit is contained in:
parent
9e47c562a5
commit
0735d3ed3a
|
@ -14,14 +14,18 @@ function createEdgeForObject<T extends PlainJSObject>(
|
|||
value: T,
|
||||
setValue: Dispatch<SetStateAction<T>>
|
||||
): T {
|
||||
const keys = Object.keys(value);
|
||||
// @ts-expect-error
|
||||
const edge: T = {};
|
||||
for (let key of keys) {
|
||||
for (let [key, keyValue] of Object.entries(value)) {
|
||||
const set = (next: SetStateAction<typeof keyValue>) => {
|
||||
const v = typeof next === 'function' ? next(keyValue) : next;
|
||||
setValue((value) => ({ ...value, [key]: v }));
|
||||
};
|
||||
|
||||
Object.defineProperty(edge, key, {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => value[key],
|
||||
get: () => createEdge(keyValue, set),
|
||||
set: (v) => void setValue((value) => ({ ...value, [key]: v })),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user