mirror of
https://github.com/towfiqi/serpbear
synced 2025-06-26 18:15:54 +00:00
refactor: improves Performance & Code Readability
- Replaces useEffet with useMemo & useLayoutEffect where necessary. - Converts some useEffects to separate hooks. - Moves the functions defined within components to utils. - Splits the Keywords renderPosition function to its own component.
This commit is contained in:
@@ -153,3 +153,23 @@ export function useRefreshKeywords(onSuccess:Function) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useFetchSingleKeyword(keywordID:number) {
|
||||
return useQuery(['keyword', keywordID], async () => {
|
||||
try {
|
||||
const fetchURL = `${window.location.origin}/api/keyword?id=${keywordID}`;
|
||||
const res = await fetch(fetchURL, { method: 'GET' }).then((result) => result.json());
|
||||
if (res.status >= 400 && res.status < 600) {
|
||||
throw new Error('Bad response from server');
|
||||
}
|
||||
return { history: res.keyword.history || [], searchResult: res.keyword.lastResult || [] };
|
||||
} catch (error) {
|
||||
throw new Error('Error Loading Keyword Details');
|
||||
}
|
||||
}, {
|
||||
onError: () => {
|
||||
console.log('Error Loading Keyword Data!!!');
|
||||
toast('Error Loading Keyword Details.', { icon: '⚠️' });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user