fix(history,workout-builder): memoize async load functions with useCallback
This commit is contained in:
@@ -27,15 +27,15 @@ export function HistoryScreen() {
|
|||||||
const [sessions, setSessions] = useState<SessionRow[]>([]);
|
const [sessions, setSessions] = useState<SessionRow[]>([]);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
|
|
||||||
const loadSessions = async () => {
|
const loadSessions = useCallback(async () => {
|
||||||
const data = await getAllSessions();
|
const data = await getAllSessions();
|
||||||
setSessions(data as SessionRow[]);
|
setSessions(data as SessionRow[]);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
loadSessions();
|
loadSessions();
|
||||||
}, [])
|
}, [loadSessions])
|
||||||
);
|
);
|
||||||
|
|
||||||
const onRefresh = async () => {
|
const onRefresh = async () => {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export function WorkoutListScreen() {
|
|||||||
const [workouts, setWorkouts] = useState<WorkoutRow[]>([]);
|
const [workouts, setWorkouts] = useState<WorkoutRow[]>([]);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
|
|
||||||
const loadWorkouts = async () => {
|
const loadWorkouts = useCallback(async () => {
|
||||||
const data = await getAllWorkouts();
|
const data = await getAllWorkouts();
|
||||||
const rows = data as WorkoutRow[];
|
const rows = data as WorkoutRow[];
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ export function WorkoutListScreen() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
setWorkouts(withDistance);
|
setWorkouts(withDistance);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
loadWorkouts();
|
loadWorkouts();
|
||||||
}, [])
|
}, [loadWorkouts])
|
||||||
);
|
);
|
||||||
|
|
||||||
const onRefresh = async () => {
|
const onRefresh = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user