Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3432 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React, { createContext, useCallback } from 'react';

import { useFetch } from '@hooks';

export const MyProgressContext = createContext();

export default function MyProgressProvider({ children }) {
  const { data: habits, isLoading: loading } = useFetch('/helpers/habits-and-skills/my', []);

  const getHabitById = useCallback(
    (habitId) => habits.find((habit) => habit.uuid === habitId),
    [habits]
  );

  return (
    <MyProgressContext.Provider value={{ loading, habits, getHabitById }}>
      {children}
    </MyProgressContext.Provider>
  );
}