Skip to content

Commit

Permalink
refactor: 수동 timer 대신 useInterval 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Nov 25, 2021
1 parent a1704a6 commit d6f808e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/presentation/features/booking/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import colors from '../../../res/colors';
import palette from '../../../res/palette';
import useStores from '../../../hooks/useStores';
import {observer} from 'mobx-react';
import useInterval from '../../../hooks/useInterval';
import BookingItem from './BookingItem';
import handleApiError from '../../../../common/utils/handleApiError';
import NoBookingsView from './NoBookingsView';
Expand All @@ -39,25 +40,19 @@ function History({navigation}: Props) {
const {bookingStore} = useStores();

const [loading, fetch] = useApi(() => bookingStore.fetchMyBookings());
const [_, refresh] = useApi(() => bookingStore.fetchMyBookings());
const [, refresh] = useApi(() => bookingStore.fetchMyBookings());

const myBookings = bookingStore.myBookings;
const getMyBookings = () => fetch().catch(handleApiError);
const silentRefresh = () => refresh().catch();

const timer = () => {
setTimeout(() => {
silentRefresh();

timer();
}, 1000);
};

useEffect(() => {
getMyBookings();
timer();
}, []);

useInterval(() => {
refresh().catch();
}, 1000 /* 1초에 한번씩 */);

const emptyView = <NoBookingsView />;

const content = (
Expand Down

0 comments on commit d6f808e

Please sign in to comment.