|
1 | 1 | 'use client' |
2 | 2 |
|
3 | | -import { useState, useEffect } from 'react' |
| 3 | +import { useState, useEffect, useCallback } from 'react' |
4 | 4 | import DataTable, { Column } from '@/app/components/DataTable' |
5 | 5 | import Icon from '@/app/components/Icon' |
6 | 6 | import Link from 'next/link' |
@@ -54,23 +54,7 @@ export default function ThirdPartiesPage() { |
54 | 54 | sortOrder: 'asc' |
55 | 55 | }) |
56 | 56 |
|
57 | | - useEffect(() => { |
58 | | - fetchThirdParties() |
59 | | - fetchInformationAssets() |
60 | | - }, []) |
61 | | - |
62 | | - // Handle filter changes |
63 | | - const handleFilterChange = (newFilters: any) => { |
64 | | - setFilters(prev => ({ ...prev, ...newFilters })) |
65 | | - fetchThirdParties(1, { ...filters, ...newFilters }) |
66 | | - } |
67 | | - |
68 | | - // Handle pagination |
69 | | - const handlePageChange = (newPage: number) => { |
70 | | - fetchThirdParties(newPage, filters) |
71 | | - } |
72 | | - |
73 | | - const fetchThirdParties = async (page = 1, newFilters = filters) => { |
| 57 | + const fetchThirdParties = useCallback(async (page = 1, newFilters = filters) => { |
74 | 58 | try { |
75 | 59 | setLoading(true) |
76 | 60 |
|
@@ -101,19 +85,35 @@ export default function ThirdPartiesPage() { |
101 | 85 | } finally { |
102 | 86 | setLoading(false) |
103 | 87 | } |
104 | | - } |
| 88 | + }, [filters, pagination.limit]) |
105 | 89 |
|
106 | | - const fetchInformationAssets = async () => { |
| 90 | + const fetchInformationAssets = useCallback(async () => { |
107 | 91 | try { |
108 | 92 | const response = await fetch('/api/information-assets') |
109 | 93 | const result = await response.json() |
110 | 94 |
|
111 | 95 | if (result.success) { |
112 | 96 | setInformationAssets(result.data) |
113 | 97 | } |
114 | | - } catch (error) { |
115 | | - console.error('Error fetching information assets:', error) |
| 98 | + } catch (err) { |
| 99 | + console.error('Error fetching information assets:', err) |
116 | 100 | } |
| 101 | + }, []) |
| 102 | + |
| 103 | + useEffect(() => { |
| 104 | + fetchThirdParties() |
| 105 | + fetchInformationAssets() |
| 106 | + }, [fetchThirdParties, fetchInformationAssets]) |
| 107 | + |
| 108 | + // Handle filter changes |
| 109 | + const handleFilterChange = (newFilters: any) => { |
| 110 | + setFilters(prev => ({ ...prev, ...newFilters })) |
| 111 | + fetchThirdParties(1, { ...filters, ...newFilters }) |
| 112 | + } |
| 113 | + |
| 114 | + // Handle pagination |
| 115 | + const handlePageChange = (newPage: number) => { |
| 116 | + fetchThirdParties(newPage, filters) |
117 | 117 | } |
118 | 118 |
|
119 | 119 |
|
|
0 commit comments