I am fetching data from the api using a createAsyncThunk action function. I created a custom hook to call this dispath function everytime:
export default function useFetchTransactionHistory() {
const dispatch = useDispatch<AppDispatch>();
return new Promise(async (resolve, reject)=> {
try {
const res:any = await dispatch(fetchTransactionsHistory());
if(res.code === 200) return(res.data);
}
catch (error) {
console.log(error);
}
})
}
The issue i'm facing is that it runs twice when I import it to use in my component
export default function TransactionHistory = ()=> {
const { data, isLoading } = useFetchTransactionHistory();
return(
<div>{data}</div>
);
}