next-recomponents 2.0.36 → 2.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -36407,140 +36407,152 @@ function useResources({
36407
36407
  return error;
36408
36408
  }
36409
36409
  };
36410
+ const mergeDataArray = (existingData, newItem, matchId) => {
36411
+ if (!existingData) return [newItem];
36412
+ const index = existingData.findIndex((d) => (d == null ? void 0 : d.id) == matchId);
36413
+ if (index >= 0) {
36414
+ return existingData.map(
36415
+ (d, i) => i === index ? newItem : d
36416
+ );
36417
+ }
36418
+ return [newItem, ...existingData];
36419
+ };
36410
36420
  const bodyCreateFunc = async (data) => {
36411
- var _a2, _b2, _c2, _d2, _e2, _f2;
36421
+ var _a2, _b2, _c2, _d2, _e2;
36412
36422
  const options = {
36413
36423
  method: "POST",
36414
36424
  url: `${baseURI}/${key}`,
36415
36425
  data: Array.isArray(data) ? [...data] : { ...data },
36416
36426
  headers: { Authorization: token }
36417
36427
  };
36418
- const newInfo = { ...info };
36419
- newInfo[key].state = "loading";
36420
- newInfo[key].errorMessage = "";
36428
+ const newInfo = {
36429
+ ...info,
36430
+ [key]: {
36431
+ ...info[key],
36432
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36433
+ state: "loading",
36434
+ errorMessage: ""
36435
+ }
36436
+ };
36421
36437
  setInfo(newInfo);
36422
36438
  try {
36423
36439
  const consulta = await import_axios.default.request(options);
36424
36440
  const d = consulta.data;
36425
- newInfo[key].state = "success";
36426
- newInfo[key].errorMessage = "";
36441
+ let updatedData;
36427
36442
  if (Array.isArray(data)) {
36428
- for (let datum of data) {
36429
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36430
- (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36431
- );
36432
- if (index >= 0) {
36433
- newInfo[key].data[index] = d;
36434
- } else {
36435
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36436
- newInfo[key].data.unshift(d);
36437
- } else {
36438
- newInfo[key].data = [d];
36439
- }
36440
- }
36443
+ updatedData = [...(_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) != null ? _d2 : []];
36444
+ for (const datum of data) {
36445
+ updatedData = mergeDataArray(updatedData, d, datum == null ? void 0 : datum.id);
36441
36446
  }
36442
- newInfo[key].data = newInfo[key].data.flat();
36447
+ updatedData = updatedData.flat();
36443
36448
  } else {
36444
- newInfo[key].selectedItem = d;
36445
- const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36446
- (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36449
+ updatedData = mergeDataArray(
36450
+ (_e2 = newInfo[key]) == null ? void 0 : _e2.data,
36451
+ d,
36452
+ data == null ? void 0 : data.id
36447
36453
  );
36448
- if (index >= 0) {
36449
- newInfo[key].data[index] = d;
36450
- } else {
36451
- if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36452
- newInfo[key].data.unshift(d);
36453
- } else {
36454
- newInfo[key].data = [d];
36455
- }
36456
- }
36457
36454
  }
36458
- setInfo({ ...newInfo });
36455
+ setInfo({
36456
+ ...newInfo,
36457
+ [key]: {
36458
+ ...newInfo[key],
36459
+ state: "success",
36460
+ errorMessage: "",
36461
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
36462
+ data: updatedData
36463
+ }
36464
+ });
36459
36465
  return d;
36460
36466
  } catch (error) {
36461
36467
  const item = http_codes_default.find((s) => s.code == error.status);
36462
- newInfo[key].state = "error";
36463
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36464
36468
  if (error.status == 403) {
36465
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36469
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36466
36470
  }
36467
- setInfo({ ...newInfo });
36471
+ setInfo({
36472
+ ...newInfo,
36473
+ [key]: {
36474
+ ...newInfo[key],
36475
+ state: "error",
36476
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36477
+ }
36478
+ });
36468
36479
  return error;
36469
36480
  }
36470
36481
  };
36471
36482
  const formCreateFunc = async (data) => {
36472
- var _a2, _b2, _c2, _d2, _e2, _f2;
36473
- const newInfo = { ...info };
36474
- newInfo[key].state = "loading";
36475
- newInfo[key].errorMessage = "";
36476
- setInfo(newInfo);
36477
- try {
36478
- const formData = new FormData();
36479
- if (Array.isArray(data)) {
36480
- data.forEach((item, i) => {
36481
- for (const [k, v] of Object.entries(item)) {
36482
- formData.append(`${k}[${i}]`, v);
36483
- }
36484
- });
36485
- } else {
36486
- for (const [k, v] of Object.entries(data)) {
36487
- formData.append(k, v);
36483
+ var _a2, _b2, _c2, _d2, _e2;
36484
+ const formData = new FormData();
36485
+ if (Array.isArray(data)) {
36486
+ data.forEach((item, i) => {
36487
+ for (const [k, v] of Object.entries(item)) {
36488
+ formData.append(`${k}[${i}]`, v);
36488
36489
  }
36490
+ });
36491
+ } else {
36492
+ for (const [k, v] of Object.entries(data)) {
36493
+ formData.append(k, v);
36489
36494
  }
36490
- const options = {
36491
- method: "POST",
36492
- url: `${baseURI}/${key}`,
36493
- data: formData,
36494
- headers: {
36495
- Authorization: token,
36496
- "Content-Type": "multipart/form-data"
36497
- }
36498
- };
36495
+ }
36496
+ const options = {
36497
+ method: "POST",
36498
+ url: `${baseURI}/${key}`,
36499
+ data: formData,
36500
+ headers: {
36501
+ Authorization: token,
36502
+ "Content-Type": "multipart/form-data"
36503
+ }
36504
+ };
36505
+ const newInfo = {
36506
+ ...info,
36507
+ [key]: {
36508
+ ...info[key],
36509
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36510
+ state: "loading",
36511
+ errorMessage: ""
36512
+ }
36513
+ };
36514
+ setInfo(newInfo);
36515
+ try {
36499
36516
  const consulta = await import_axios.default.request(options);
36500
36517
  const d = consulta.data;
36501
- newInfo[key].state = "success";
36502
- newInfo[key].errorMessage = "";
36518
+ let updatedData;
36503
36519
  if (Array.isArray(data)) {
36504
- for (let datum of data) {
36505
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36506
- (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36507
- );
36508
- if (index >= 0) {
36509
- newInfo[key].data[index] = d;
36510
- } else {
36511
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36512
- newInfo[key].data.unshift(d);
36513
- } else {
36514
- newInfo[key].data = [d];
36515
- }
36516
- }
36520
+ updatedData = [...(_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) != null ? _d2 : []];
36521
+ for (const datum of data) {
36522
+ updatedData = mergeDataArray(updatedData, d, datum == null ? void 0 : datum.id);
36517
36523
  }
36518
- newInfo[key].data = newInfo[key].data.flat();
36524
+ updatedData = updatedData.flat();
36519
36525
  } else {
36520
- newInfo[key].selectedItem = d;
36521
- const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36522
- (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36526
+ updatedData = mergeDataArray(
36527
+ (_e2 = newInfo[key]) == null ? void 0 : _e2.data,
36528
+ d,
36529
+ data == null ? void 0 : data.id
36523
36530
  );
36524
- if (index >= 0) {
36525
- newInfo[key].data[index] = d;
36526
- } else {
36527
- if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36528
- newInfo[key].data.unshift(d);
36529
- } else {
36530
- newInfo[key].data = [d];
36531
- }
36532
- }
36533
36531
  }
36534
- setInfo({ ...newInfo });
36532
+ setInfo({
36533
+ ...newInfo,
36534
+ [key]: {
36535
+ ...newInfo[key],
36536
+ state: "success",
36537
+ errorMessage: "",
36538
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
36539
+ data: updatedData
36540
+ }
36541
+ });
36535
36542
  return d;
36536
36543
  } catch (error) {
36537
36544
  const item = http_codes_default.find((s) => s.code == error.status);
36538
- newInfo[key].state = "error";
36539
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36540
36545
  if (error.status == 403) {
36541
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36546
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36542
36547
  }
36543
- setInfo({ ...newInfo });
36548
+ setInfo({
36549
+ ...newInfo,
36550
+ [key]: {
36551
+ ...newInfo[key],
36552
+ state: "error",
36553
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36554
+ }
36555
+ });
36544
36556
  return error;
36545
36557
  }
36546
36558
  };
@@ -36559,81 +36571,107 @@ function useResources({
36559
36571
  return await bodyCreateFunc(data);
36560
36572
  },
36561
36573
  update: async (id, data) => {
36562
- var _a2, _b2, _c2;
36574
+ var _a2, _b2, _c2, _d2, _e2;
36563
36575
  const options = {
36564
36576
  method: "PATCH",
36565
36577
  url: `${baseURI}/${key}/${id}`,
36566
36578
  data: Array.isArray(data) ? [...data] : { ...data },
36567
36579
  headers: { Authorization: token }
36568
36580
  };
36569
- const newInfo = { ...info };
36570
- newInfo[key].state = "loading";
36571
- newInfo[key].errorMessage = "";
36581
+ const newInfo = {
36582
+ ...info,
36583
+ [key]: {
36584
+ ...info[key],
36585
+ // ✅ copia superficial del key
36586
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36587
+ // ✅ copia del array
36588
+ state: "loading",
36589
+ errorMessage: ""
36590
+ }
36591
+ };
36572
36592
  setInfo(newInfo);
36573
36593
  try {
36574
36594
  const consulta = await import_axios.default.request(options);
36575
36595
  const d = consulta.data;
36576
- newInfo[key].state = "success";
36577
- newInfo[key].errorMessage = "";
36578
- newInfo[key].selectedItem = { ...newInfo[key].selectedItem, ...d };
36579
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36580
- (d2) => (d2 == null ? void 0 : d2.id) == id
36596
+ const index = (_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) == null ? void 0 : _d2.findIndex(
36597
+ (item) => (item == null ? void 0 : item.id) == id
36581
36598
  );
36582
- if (index >= 0) {
36583
- newInfo[key].data[index] = { ...newInfo[key].data[index], ...d };
36584
- } else {
36585
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36586
- newInfo[key].data.unshift(d);
36587
- } else {
36588
- newInfo[key].data = [d];
36599
+ const updatedData = index >= 0 ? newInfo[key].data.map(
36600
+ (item, i) => i === index ? { ...item, ...d } : item
36601
+ ) : ((_e2 = newInfo[key]) == null ? void 0 : _e2.data) ? [d, ...newInfo[key].data] : [d];
36602
+ const updatedInfo = {
36603
+ ...newInfo,
36604
+ [key]: {
36605
+ ...newInfo[key],
36606
+ state: "success",
36607
+ errorMessage: "",
36608
+ selectedItem: { ...newInfo[key].selectedItem, ...d },
36609
+ data: updatedData
36589
36610
  }
36590
- }
36591
- setInfo({ ...newInfo });
36611
+ };
36612
+ setInfo(updatedInfo);
36592
36613
  return d;
36593
36614
  } catch (error) {
36594
36615
  const item = http_codes_default.find((s) => s.code == error.status);
36595
- newInfo[key].state = "error";
36596
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36616
+ setInfo({
36617
+ ...newInfo,
36618
+ [key]: {
36619
+ ...newInfo[key],
36620
+ state: "error",
36621
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36622
+ }
36623
+ });
36597
36624
  if (error.status == 403) {
36598
36625
  onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36599
36626
  }
36600
- setInfo({ ...newInfo });
36601
36627
  return error;
36602
36628
  }
36603
36629
  },
36604
36630
  remove: async (id) => {
36605
- var _a2, _b2;
36631
+ var _a2, _b2, _c2, _d2, _e2;
36606
36632
  const options = {
36607
36633
  method: "DELETE",
36608
36634
  url: `${baseURI}/${key}/${id}`,
36609
36635
  headers: { Authorization: token }
36610
36636
  };
36611
- const newInfo = { ...info };
36612
- newInfo[key].state = "loading";
36613
- newInfo[key].errorMessage = "";
36637
+ const newInfo = {
36638
+ ...info,
36639
+ [key]: {
36640
+ ...info[key],
36641
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36642
+ state: "loading",
36643
+ errorMessage: ""
36644
+ }
36645
+ };
36614
36646
  setInfo(newInfo);
36615
36647
  try {
36616
36648
  const consulta = await import_axios.default.request(options);
36617
36649
  const d = consulta.data;
36618
- newInfo[key].state = "success";
36619
- newInfo[key].errorMessage = "";
36620
- newInfo[key].selectedItem = d;
36621
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36622
- (d2) => (d2 == null ? void 0 : d2.id) == id
36623
- );
36624
- if (index >= 0) {
36625
- newInfo[key].data.splice(index, 1);
36626
- }
36627
- setInfo({ ...newInfo });
36650
+ setInfo({
36651
+ ...newInfo,
36652
+ [key]: {
36653
+ ...newInfo[key],
36654
+ state: "success",
36655
+ errorMessage: "",
36656
+ selectedItem: d,
36657
+ data: (_e2 = (_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) == null ? void 0 : _d2.filter((item) => (item == null ? void 0 : item.id) != id)) != null ? _e2 : []
36658
+ // ✅ filter en lugar de splice
36659
+ }
36660
+ });
36628
36661
  return d.data;
36629
36662
  } catch (error) {
36630
36663
  const item = http_codes_default.find((s) => s.code == error.status);
36631
- newInfo[key].state = "error";
36632
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36633
36664
  if (error.status == 403) {
36634
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36665
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36635
36666
  }
36636
- setInfo({ ...newInfo });
36667
+ setInfo({
36668
+ ...newInfo,
36669
+ [key]: {
36670
+ ...newInfo[key],
36671
+ state: "error",
36672
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36673
+ }
36674
+ });
36637
36675
  return error;
36638
36676
  }
36639
36677
  },
package/dist/index.mjs CHANGED
@@ -36389,140 +36389,152 @@ function useResources({
36389
36389
  return error;
36390
36390
  }
36391
36391
  };
36392
+ const mergeDataArray = (existingData, newItem, matchId) => {
36393
+ if (!existingData) return [newItem];
36394
+ const index = existingData.findIndex((d) => (d == null ? void 0 : d.id) == matchId);
36395
+ if (index >= 0) {
36396
+ return existingData.map(
36397
+ (d, i) => i === index ? newItem : d
36398
+ );
36399
+ }
36400
+ return [newItem, ...existingData];
36401
+ };
36392
36402
  const bodyCreateFunc = async (data) => {
36393
- var _a2, _b2, _c2, _d2, _e2, _f2;
36403
+ var _a2, _b2, _c2, _d2, _e2;
36394
36404
  const options = {
36395
36405
  method: "POST",
36396
36406
  url: `${baseURI}/${key}`,
36397
36407
  data: Array.isArray(data) ? [...data] : { ...data },
36398
36408
  headers: { Authorization: token }
36399
36409
  };
36400
- const newInfo = { ...info };
36401
- newInfo[key].state = "loading";
36402
- newInfo[key].errorMessage = "";
36410
+ const newInfo = {
36411
+ ...info,
36412
+ [key]: {
36413
+ ...info[key],
36414
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36415
+ state: "loading",
36416
+ errorMessage: ""
36417
+ }
36418
+ };
36403
36419
  setInfo(newInfo);
36404
36420
  try {
36405
36421
  const consulta = await axios.request(options);
36406
36422
  const d = consulta.data;
36407
- newInfo[key].state = "success";
36408
- newInfo[key].errorMessage = "";
36423
+ let updatedData;
36409
36424
  if (Array.isArray(data)) {
36410
- for (let datum of data) {
36411
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36412
- (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36413
- );
36414
- if (index >= 0) {
36415
- newInfo[key].data[index] = d;
36416
- } else {
36417
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36418
- newInfo[key].data.unshift(d);
36419
- } else {
36420
- newInfo[key].data = [d];
36421
- }
36422
- }
36425
+ updatedData = [...(_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) != null ? _d2 : []];
36426
+ for (const datum of data) {
36427
+ updatedData = mergeDataArray(updatedData, d, datum == null ? void 0 : datum.id);
36423
36428
  }
36424
- newInfo[key].data = newInfo[key].data.flat();
36429
+ updatedData = updatedData.flat();
36425
36430
  } else {
36426
- newInfo[key].selectedItem = d;
36427
- const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36428
- (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36431
+ updatedData = mergeDataArray(
36432
+ (_e2 = newInfo[key]) == null ? void 0 : _e2.data,
36433
+ d,
36434
+ data == null ? void 0 : data.id
36429
36435
  );
36430
- if (index >= 0) {
36431
- newInfo[key].data[index] = d;
36432
- } else {
36433
- if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36434
- newInfo[key].data.unshift(d);
36435
- } else {
36436
- newInfo[key].data = [d];
36437
- }
36438
- }
36439
36436
  }
36440
- setInfo({ ...newInfo });
36437
+ setInfo({
36438
+ ...newInfo,
36439
+ [key]: {
36440
+ ...newInfo[key],
36441
+ state: "success",
36442
+ errorMessage: "",
36443
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
36444
+ data: updatedData
36445
+ }
36446
+ });
36441
36447
  return d;
36442
36448
  } catch (error) {
36443
36449
  const item = http_codes_default.find((s) => s.code == error.status);
36444
- newInfo[key].state = "error";
36445
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36446
36450
  if (error.status == 403) {
36447
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36451
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36448
36452
  }
36449
- setInfo({ ...newInfo });
36453
+ setInfo({
36454
+ ...newInfo,
36455
+ [key]: {
36456
+ ...newInfo[key],
36457
+ state: "error",
36458
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36459
+ }
36460
+ });
36450
36461
  return error;
36451
36462
  }
36452
36463
  };
36453
36464
  const formCreateFunc = async (data) => {
36454
- var _a2, _b2, _c2, _d2, _e2, _f2;
36455
- const newInfo = { ...info };
36456
- newInfo[key].state = "loading";
36457
- newInfo[key].errorMessage = "";
36458
- setInfo(newInfo);
36459
- try {
36460
- const formData = new FormData();
36461
- if (Array.isArray(data)) {
36462
- data.forEach((item, i) => {
36463
- for (const [k, v] of Object.entries(item)) {
36464
- formData.append(`${k}[${i}]`, v);
36465
- }
36466
- });
36467
- } else {
36468
- for (const [k, v] of Object.entries(data)) {
36469
- formData.append(k, v);
36465
+ var _a2, _b2, _c2, _d2, _e2;
36466
+ const formData = new FormData();
36467
+ if (Array.isArray(data)) {
36468
+ data.forEach((item, i) => {
36469
+ for (const [k, v] of Object.entries(item)) {
36470
+ formData.append(`${k}[${i}]`, v);
36470
36471
  }
36472
+ });
36473
+ } else {
36474
+ for (const [k, v] of Object.entries(data)) {
36475
+ formData.append(k, v);
36471
36476
  }
36472
- const options = {
36473
- method: "POST",
36474
- url: `${baseURI}/${key}`,
36475
- data: formData,
36476
- headers: {
36477
- Authorization: token,
36478
- "Content-Type": "multipart/form-data"
36479
- }
36480
- };
36477
+ }
36478
+ const options = {
36479
+ method: "POST",
36480
+ url: `${baseURI}/${key}`,
36481
+ data: formData,
36482
+ headers: {
36483
+ Authorization: token,
36484
+ "Content-Type": "multipart/form-data"
36485
+ }
36486
+ };
36487
+ const newInfo = {
36488
+ ...info,
36489
+ [key]: {
36490
+ ...info[key],
36491
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36492
+ state: "loading",
36493
+ errorMessage: ""
36494
+ }
36495
+ };
36496
+ setInfo(newInfo);
36497
+ try {
36481
36498
  const consulta = await axios.request(options);
36482
36499
  const d = consulta.data;
36483
- newInfo[key].state = "success";
36484
- newInfo[key].errorMessage = "";
36500
+ let updatedData;
36485
36501
  if (Array.isArray(data)) {
36486
- for (let datum of data) {
36487
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36488
- (d2) => (d2 == null ? void 0 : d2.id) == (datum == null ? void 0 : datum.id)
36489
- );
36490
- if (index >= 0) {
36491
- newInfo[key].data[index] = d;
36492
- } else {
36493
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36494
- newInfo[key].data.unshift(d);
36495
- } else {
36496
- newInfo[key].data = [d];
36497
- }
36498
- }
36502
+ updatedData = [...(_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) != null ? _d2 : []];
36503
+ for (const datum of data) {
36504
+ updatedData = mergeDataArray(updatedData, d, datum == null ? void 0 : datum.id);
36499
36505
  }
36500
- newInfo[key].data = newInfo[key].data.flat();
36506
+ updatedData = updatedData.flat();
36501
36507
  } else {
36502
- newInfo[key].selectedItem = d;
36503
- const index = (_e2 = (_d2 = newInfo[key]) == null ? void 0 : _d2.data) == null ? void 0 : _e2.findIndex(
36504
- (d2) => (d2 == null ? void 0 : d2.id) == (data == null ? void 0 : data.id)
36508
+ updatedData = mergeDataArray(
36509
+ (_e2 = newInfo[key]) == null ? void 0 : _e2.data,
36510
+ d,
36511
+ data == null ? void 0 : data.id
36505
36512
  );
36506
- if (index >= 0) {
36507
- newInfo[key].data[index] = d;
36508
- } else {
36509
- if ((_f2 = newInfo[key]) == null ? void 0 : _f2.data) {
36510
- newInfo[key].data.unshift(d);
36511
- } else {
36512
- newInfo[key].data = [d];
36513
- }
36514
- }
36515
36513
  }
36516
- setInfo({ ...newInfo });
36514
+ setInfo({
36515
+ ...newInfo,
36516
+ [key]: {
36517
+ ...newInfo[key],
36518
+ state: "success",
36519
+ errorMessage: "",
36520
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
36521
+ data: updatedData
36522
+ }
36523
+ });
36517
36524
  return d;
36518
36525
  } catch (error) {
36519
36526
  const item = http_codes_default.find((s) => s.code == error.status);
36520
- newInfo[key].state = "error";
36521
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36522
36527
  if (error.status == 403) {
36523
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36528
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36524
36529
  }
36525
- setInfo({ ...newInfo });
36530
+ setInfo({
36531
+ ...newInfo,
36532
+ [key]: {
36533
+ ...newInfo[key],
36534
+ state: "error",
36535
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36536
+ }
36537
+ });
36526
36538
  return error;
36527
36539
  }
36528
36540
  };
@@ -36541,81 +36553,107 @@ function useResources({
36541
36553
  return await bodyCreateFunc(data);
36542
36554
  },
36543
36555
  update: async (id, data) => {
36544
- var _a2, _b2, _c2;
36556
+ var _a2, _b2, _c2, _d2, _e2;
36545
36557
  const options = {
36546
36558
  method: "PATCH",
36547
36559
  url: `${baseURI}/${key}/${id}`,
36548
36560
  data: Array.isArray(data) ? [...data] : { ...data },
36549
36561
  headers: { Authorization: token }
36550
36562
  };
36551
- const newInfo = { ...info };
36552
- newInfo[key].state = "loading";
36553
- newInfo[key].errorMessage = "";
36563
+ const newInfo = {
36564
+ ...info,
36565
+ [key]: {
36566
+ ...info[key],
36567
+ // ✅ copia superficial del key
36568
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36569
+ // ✅ copia del array
36570
+ state: "loading",
36571
+ errorMessage: ""
36572
+ }
36573
+ };
36554
36574
  setInfo(newInfo);
36555
36575
  try {
36556
36576
  const consulta = await axios.request(options);
36557
36577
  const d = consulta.data;
36558
- newInfo[key].state = "success";
36559
- newInfo[key].errorMessage = "";
36560
- newInfo[key].selectedItem = { ...newInfo[key].selectedItem, ...d };
36561
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36562
- (d2) => (d2 == null ? void 0 : d2.id) == id
36578
+ const index = (_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) == null ? void 0 : _d2.findIndex(
36579
+ (item) => (item == null ? void 0 : item.id) == id
36563
36580
  );
36564
- if (index >= 0) {
36565
- newInfo[key].data[index] = { ...newInfo[key].data[index], ...d };
36566
- } else {
36567
- if ((_c2 = newInfo[key]) == null ? void 0 : _c2.data) {
36568
- newInfo[key].data.unshift(d);
36569
- } else {
36570
- newInfo[key].data = [d];
36581
+ const updatedData = index >= 0 ? newInfo[key].data.map(
36582
+ (item, i) => i === index ? { ...item, ...d } : item
36583
+ ) : ((_e2 = newInfo[key]) == null ? void 0 : _e2.data) ? [d, ...newInfo[key].data] : [d];
36584
+ const updatedInfo = {
36585
+ ...newInfo,
36586
+ [key]: {
36587
+ ...newInfo[key],
36588
+ state: "success",
36589
+ errorMessage: "",
36590
+ selectedItem: { ...newInfo[key].selectedItem, ...d },
36591
+ data: updatedData
36571
36592
  }
36572
- }
36573
- setInfo({ ...newInfo });
36593
+ };
36594
+ setInfo(updatedInfo);
36574
36595
  return d;
36575
36596
  } catch (error) {
36576
36597
  const item = http_codes_default.find((s) => s.code == error.status);
36577
- newInfo[key].state = "error";
36578
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36598
+ setInfo({
36599
+ ...newInfo,
36600
+ [key]: {
36601
+ ...newInfo[key],
36602
+ state: "error",
36603
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36604
+ }
36605
+ });
36579
36606
  if (error.status == 403) {
36580
36607
  onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36581
36608
  }
36582
- setInfo({ ...newInfo });
36583
36609
  return error;
36584
36610
  }
36585
36611
  },
36586
36612
  remove: async (id) => {
36587
- var _a2, _b2;
36613
+ var _a2, _b2, _c2, _d2, _e2;
36588
36614
  const options = {
36589
36615
  method: "DELETE",
36590
36616
  url: `${baseURI}/${key}/${id}`,
36591
36617
  headers: { Authorization: token }
36592
36618
  };
36593
- const newInfo = { ...info };
36594
- newInfo[key].state = "loading";
36595
- newInfo[key].errorMessage = "";
36619
+ const newInfo = {
36620
+ ...info,
36621
+ [key]: {
36622
+ ...info[key],
36623
+ data: [...(_b2 = (_a2 = info[key]) == null ? void 0 : _a2.data) != null ? _b2 : []],
36624
+ state: "loading",
36625
+ errorMessage: ""
36626
+ }
36627
+ };
36596
36628
  setInfo(newInfo);
36597
36629
  try {
36598
36630
  const consulta = await axios.request(options);
36599
36631
  const d = consulta.data;
36600
- newInfo[key].state = "success";
36601
- newInfo[key].errorMessage = "";
36602
- newInfo[key].selectedItem = d;
36603
- const index = (_b2 = (_a2 = newInfo[key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.findIndex(
36604
- (d2) => (d2 == null ? void 0 : d2.id) == id
36605
- );
36606
- if (index >= 0) {
36607
- newInfo[key].data.splice(index, 1);
36608
- }
36609
- setInfo({ ...newInfo });
36632
+ setInfo({
36633
+ ...newInfo,
36634
+ [key]: {
36635
+ ...newInfo[key],
36636
+ state: "success",
36637
+ errorMessage: "",
36638
+ selectedItem: d,
36639
+ data: (_e2 = (_d2 = (_c2 = newInfo[key]) == null ? void 0 : _c2.data) == null ? void 0 : _d2.filter((item) => (item == null ? void 0 : item.id) != id)) != null ? _e2 : []
36640
+ // ✅ filter en lugar de splice
36641
+ }
36642
+ });
36610
36643
  return d.data;
36611
36644
  } catch (error) {
36612
36645
  const item = http_codes_default.find((s) => s.code == error.status);
36613
- newInfo[key].state = "error";
36614
- newInfo[key].errorMessage = (item == null ? void 0 : item.meaning) || error.message;
36615
36646
  if (error.status == 403) {
36616
- onError == null ? void 0 : onError({ error, ...{ errorMessage: item == null ? void 0 : item.meaning } });
36647
+ onError == null ? void 0 : onError({ error, errorMessage: item == null ? void 0 : item.meaning });
36617
36648
  }
36618
- setInfo({ ...newInfo });
36649
+ setInfo({
36650
+ ...newInfo,
36651
+ [key]: {
36652
+ ...newInfo[key],
36653
+ state: "error",
36654
+ errorMessage: (item == null ? void 0 : item.meaning) || error.message
36655
+ }
36656
+ });
36619
36657
  return error;
36620
36658
  }
36621
36659
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "2.0.36",
3
+ "version": "2.0.38",
4
4
  "description": "description nueva",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -129,6 +129,22 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
129
129
  return error;
130
130
  }
131
131
  };
132
+ // Helper para actualizar el array sin mutar
133
+ const mergeDataArray = (
134
+ existingData: any[] | undefined,
135
+ newItem: any,
136
+ matchId?: any,
137
+ ): any[] => {
138
+ if (!existingData) return [newItem];
139
+ const index = existingData.findIndex((d: any) => d?.id == matchId);
140
+ if (index >= 0) {
141
+ return existingData.map((d: any, i: number) =>
142
+ i === index ? newItem : d,
143
+ );
144
+ }
145
+ return [newItem, ...existingData];
146
+ };
147
+
132
148
  const bodyCreateFunc = async (
133
149
  data: Record<string, any> | Record<string, any>[],
134
150
  ) => {
@@ -138,146 +154,158 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
138
154
  data: Array.isArray(data) ? [...data] : { ...data },
139
155
  headers: { Authorization: token },
140
156
  };
141
- const newInfo = { ...info };
142
- // newInfo[key] = newInfo[key] || {};
143
- newInfo[key].state = "loading";
144
- newInfo[key].errorMessage = "";
157
+
158
+ const newInfo = {
159
+ ...info,
160
+ [key]: {
161
+ ...info[key],
162
+ data: [...(info[key]?.data ?? [])],
163
+ state: "loading",
164
+ errorMessage: "",
165
+ },
166
+ };
145
167
 
146
168
  setInfo(newInfo);
147
169
 
148
170
  try {
149
171
  const consulta = await axios.request(options);
150
172
  const d = consulta.data;
151
- newInfo[key].state = "success";
152
- newInfo[key].errorMessage = "";
173
+
174
+ let updatedData: any[];
175
+
153
176
  if (Array.isArray(data)) {
154
- for (let datum of data) {
155
- const index = newInfo[key]?.data?.findIndex(
156
- (d: any) => d?.id == datum?.id,
157
- );
158
- if (index >= 0) {
159
- newInfo[key].data[index] = d;
160
- } else {
161
- if (newInfo[key]?.data) {
162
- newInfo[key].data.unshift(d);
163
- } else {
164
- newInfo[key].data = [d];
165
- }
166
- }
177
+ updatedData = [...(newInfo[key]?.data ?? [])];
178
+ for (const datum of data) {
179
+ updatedData = mergeDataArray(updatedData, d, datum?.id);
167
180
  }
168
- newInfo[key].data = newInfo[key].data.flat();
181
+ updatedData = updatedData.flat();
169
182
  } else {
170
- newInfo[key].selectedItem = d;
171
- const index = newInfo[key]?.data?.findIndex(
172
- (d: any) => d?.id == data?.id,
183
+ updatedData = mergeDataArray(
184
+ newInfo[key]?.data,
185
+ d,
186
+ (data as any)?.id,
173
187
  );
174
- if (index >= 0) {
175
- newInfo[key].data[index] = d;
176
- } else {
177
- if (newInfo[key]?.data) {
178
- newInfo[key].data.unshift(d);
179
- } else {
180
- newInfo[key].data = [d];
181
- }
182
- }
183
188
  }
184
- setInfo({ ...newInfo });
189
+
190
+ setInfo({
191
+ ...newInfo,
192
+ [key]: {
193
+ ...newInfo[key],
194
+ state: "success",
195
+ errorMessage: "",
196
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
197
+ data: updatedData,
198
+ },
199
+ });
200
+
185
201
  return d;
186
202
  } catch (error: any) {
187
203
  const item = httpStatusCodes.find((s) => s.code == error.status);
188
204
 
189
- newInfo[key].state = "error";
190
- newInfo[key].errorMessage = item?.meaning || error.message;
191
205
  if (error.status == 403) {
192
- onError?.({ error, ...{ errorMessage: item?.meaning } });
206
+ onError?.({ error, errorMessage: item?.meaning });
193
207
  }
194
- setInfo({ ...newInfo });
208
+
209
+ setInfo({
210
+ ...newInfo,
211
+ [key]: {
212
+ ...newInfo[key],
213
+ state: "error",
214
+ errorMessage: item?.meaning || error.message,
215
+ },
216
+ });
217
+
195
218
  return error;
196
219
  }
197
220
  };
221
+
198
222
  const formCreateFunc = async (
199
223
  data: Record<string, any> | Record<string, any>[],
200
224
  ) => {
201
- const newInfo = { ...info };
202
- newInfo[key].state = "loading";
203
- newInfo[key].errorMessage = "";
204
- setInfo(newInfo);
225
+ const formData = new FormData();
205
226
 
206
- try {
207
- // Convertir datos a FormData
208
- const formData = new FormData();
209
-
210
- if (Array.isArray(data)) {
211
- // Suponiendo que la API acepta múltiples entradas con la misma clave
212
- data.forEach((item, i) => {
213
- for (const [k, v] of Object.entries(item)) {
214
- formData.append(`${k}[${i}]`, v as any);
215
- }
216
- });
217
- } else {
218
- for (const [k, v] of Object.entries(data)) {
219
- formData.append(k, v);
227
+ if (Array.isArray(data)) {
228
+ data.forEach((item, i) => {
229
+ for (const [k, v] of Object.entries(item)) {
230
+ formData.append(`${k}[${i}]`, v as any);
220
231
  }
232
+ });
233
+ } else {
234
+ for (const [k, v] of Object.entries(data)) {
235
+ formData.append(k, v);
221
236
  }
237
+ }
222
238
 
223
- const options = {
224
- method: "POST",
225
- url: `${baseURI}/${key}`,
226
- data: formData,
227
- headers: {
228
- Authorization: token,
229
- "Content-Type": "multipart/form-data",
230
- },
231
- };
239
+ const options = {
240
+ method: "POST",
241
+ url: `${baseURI}/${key}`,
242
+ data: formData,
243
+ headers: {
244
+ Authorization: token,
245
+ "Content-Type": "multipart/form-data",
246
+ },
247
+ };
248
+
249
+ const newInfo = {
250
+ ...info,
251
+ [key]: {
252
+ ...info[key],
253
+ data: [...(info[key]?.data ?? [])],
254
+ state: "loading",
255
+ errorMessage: "",
256
+ },
257
+ };
258
+
259
+ setInfo(newInfo);
232
260
 
261
+ try {
233
262
  const consulta = await axios.request(options);
234
263
  const d = consulta.data;
235
264
 
236
- newInfo[key].state = "success";
237
- newInfo[key].errorMessage = "";
265
+ let updatedData: any[];
238
266
 
239
267
  if (Array.isArray(data)) {
240
- for (let datum of data) {
241
- const index = newInfo[key]?.data?.findIndex(
242
- (d: any) => d?.id == datum?.id,
243
- );
244
- if (index >= 0) {
245
- newInfo[key].data[index] = d;
246
- } else {
247
- if (newInfo[key]?.data) {
248
- newInfo[key].data.unshift(d);
249
- } else {
250
- newInfo[key].data = [d];
251
- }
252
- }
268
+ updatedData = [...(newInfo[key]?.data ?? [])];
269
+ for (const datum of data) {
270
+ updatedData = mergeDataArray(updatedData, d, datum?.id);
253
271
  }
254
- newInfo[key].data = newInfo[key].data.flat();
272
+ updatedData = updatedData.flat();
255
273
  } else {
256
- newInfo[key].selectedItem = d;
257
- const index = newInfo[key]?.data?.findIndex(
258
- (d: any) => d?.id == data?.id,
274
+ updatedData = mergeDataArray(
275
+ newInfo[key]?.data,
276
+ d,
277
+ (data as any)?.id,
259
278
  );
260
- if (index >= 0) {
261
- newInfo[key].data[index] = d;
262
- } else {
263
- if (newInfo[key]?.data) {
264
- newInfo[key].data.unshift(d);
265
- } else {
266
- newInfo[key].data = [d];
267
- }
268
- }
269
279
  }
270
280
 
271
- setInfo({ ...newInfo });
281
+ setInfo({
282
+ ...newInfo,
283
+ [key]: {
284
+ ...newInfo[key],
285
+ state: "success",
286
+ errorMessage: "",
287
+ selectedItem: Array.isArray(data) ? newInfo[key].selectedItem : d,
288
+ data: updatedData,
289
+ },
290
+ });
291
+
272
292
  return d;
273
293
  } catch (error: any) {
274
294
  const item = httpStatusCodes.find((s) => s.code == error.status);
275
- newInfo[key].state = "error";
276
- newInfo[key].errorMessage = item?.meaning || error.message;
295
+
277
296
  if (error.status == 403) {
278
- onError?.({ error, ...{ errorMessage: item?.meaning } });
297
+ onError?.({ error, errorMessage: item?.meaning });
279
298
  }
280
- setInfo({ ...newInfo });
299
+
300
+ setInfo({
301
+ ...newInfo,
302
+ [key]: {
303
+ ...newInfo[key],
304
+ state: "error",
305
+ errorMessage: item?.meaning || error.message,
306
+ },
307
+ });
308
+
281
309
  return error;
282
310
  }
283
311
  };
@@ -306,43 +334,68 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
306
334
  data: Array.isArray(data) ? [...data] : { ...data },
307
335
  headers: { Authorization: token },
308
336
  };
309
- const newInfo = { ...info };
310
- // newInfo[key] = newInfo[key] || {};
311
- newInfo[key].state = "loading";
312
- newInfo[key].errorMessage = "";
337
+
338
+ const newInfo = {
339
+ ...info,
340
+ [key]: {
341
+ ...info[key], // ✅ copia superficial del key
342
+ data: [...(info[key]?.data ?? [])], // ✅ copia del array
343
+ state: "loading",
344
+ errorMessage: "",
345
+ },
346
+ };
313
347
 
314
348
  setInfo(newInfo);
315
349
 
316
350
  try {
317
351
  const consulta = await axios.request(options);
318
352
  const d = consulta.data;
319
- newInfo[key].state = "success";
320
- newInfo[key].errorMessage = "";
321
- newInfo[key].selectedItem = { ...newInfo[key].selectedItem, ...d };
353
+
322
354
  const index = newInfo[key]?.data?.findIndex(
323
- (d: any) => d?.id == id,
355
+ (item: any) => item?.id == id,
324
356
  );
325
357
 
326
- if (index >= 0) {
327
- newInfo[key].data[index] = { ...newInfo[key].data[index], ...d };
328
- } else {
329
- if (newInfo[key]?.data) {
330
- newInfo[key].data.unshift(d);
331
- } else {
332
- newInfo[key].data = [d];
333
- }
334
- }
335
- setInfo({ ...newInfo });
358
+ const updatedData =
359
+ index >= 0
360
+ ? newInfo[key].data.map(
361
+ (
362
+ item: any,
363
+ i: number, // ✅ map en lugar de mutación
364
+ ) => (i === index ? { ...item, ...d } : item),
365
+ )
366
+ : newInfo[key]?.data
367
+ ? [d, ...newInfo[key].data] // ✅ nuevo array en lugar de unshift
368
+ : [d];
369
+
370
+ const updatedInfo = {
371
+ ...newInfo,
372
+ [key]: {
373
+ ...newInfo[key],
374
+ state: "success",
375
+ errorMessage: "",
376
+ selectedItem: { ...newInfo[key].selectedItem, ...d },
377
+ data: updatedData,
378
+ },
379
+ };
380
+
381
+ setInfo(updatedInfo);
336
382
  return d;
337
383
  } catch (error: any) {
338
384
  const item = httpStatusCodes.find((s) => s.code == error.status);
339
385
 
340
- newInfo[key].state = "error";
341
- newInfo[key].errorMessage = item?.meaning || error.message;
386
+ setInfo({
387
+ ...newInfo,
388
+ [key]: {
389
+ ...newInfo[key],
390
+ state: "error",
391
+ errorMessage: item?.meaning || error.message,
392
+ },
393
+ });
394
+
342
395
  if (error.status == 403) {
343
396
  onError?.({ error, ...{ errorMessage: item?.meaning } });
344
397
  }
345
- setInfo({ ...newInfo });
398
+
346
399
  return error;
347
400
  }
348
401
  },
@@ -352,36 +405,53 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
352
405
  url: `${baseURI}/${key}/${id}`,
353
406
  headers: { Authorization: token },
354
407
  };
355
- const newInfo = { ...info };
356
- // newInfo[key] = newInfo[key] || {};
357
- newInfo[key].state = "loading";
358
- newInfo[key].errorMessage = "";
408
+
409
+ const newInfo = {
410
+ ...info,
411
+ [key]: {
412
+ ...info[key],
413
+ data: [...(info[key]?.data ?? [])],
414
+ state: "loading",
415
+ errorMessage: "",
416
+ },
417
+ };
359
418
 
360
419
  setInfo(newInfo);
361
420
 
362
421
  try {
363
422
  const consulta = await axios.request(options);
364
423
  const d = consulta.data;
365
- newInfo[key].state = "success";
366
- newInfo[key].errorMessage = "";
367
- newInfo[key].selectedItem = d;
368
- const index = newInfo[key]?.data?.findIndex(
369
- (d: any) => d?.id == id,
370
- );
371
- if (index >= 0) {
372
- newInfo[key].data.splice(index, 1);
373
- }
374
- setInfo({ ...newInfo });
424
+
425
+ setInfo({
426
+ ...newInfo,
427
+ [key]: {
428
+ ...newInfo[key],
429
+ state: "success",
430
+ errorMessage: "",
431
+ selectedItem: d,
432
+ data:
433
+ newInfo[key]?.data?.filter((item: any) => item?.id != id) ??
434
+ [], // ✅ filter en lugar de splice
435
+ },
436
+ });
437
+
375
438
  return d.data;
376
439
  } catch (error: any) {
377
440
  const item = httpStatusCodes.find((s) => s.code == error.status);
378
441
 
379
- newInfo[key].state = "error";
380
- newInfo[key].errorMessage = item?.meaning || error.message;
381
442
  if (error.status == 403) {
382
- onError?.({ error, ...{ errorMessage: item?.meaning } });
443
+ onError?.({ error, errorMessage: item?.meaning });
383
444
  }
384
- setInfo({ ...newInfo });
445
+
446
+ setInfo({
447
+ ...newInfo,
448
+ [key]: {
449
+ ...newInfo[key],
450
+ state: "error",
451
+ errorMessage: item?.meaning || error.message,
452
+ },
453
+ });
454
+
385
455
  return error;
386
456
  }
387
457
  },