timetable-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

useMySubject.ts (637B)


      1 import { useLocalStorage } from 'usehooks-ts';
      2 
      3 import getSchoolYear from 'common/utils/getSchoolYear';
      4 
      5 import type { DayPeriodJa, GradeClass } from 'common/types';
      6 
      7 // ストレージのキー
      8 const getStorageKey = (gradeClass: GradeClass, dayPeriod: DayPeriodJa) => {
      9 	const schoolYear = getSchoolYear();
     10 	return `my_subject_data_${schoolYear}_${gradeClass}_${dayPeriod}`;
     11 };
     12 
     13 type Params = {
     14 	gradeClass: GradeClass;
     15 	dayPeriod: DayPeriodJa;
     16 };
     17 
     18 const useMySubject = ({ gradeClass, dayPeriod }: Params) => {
     19 	return useLocalStorage<string | null>(
     20 		getStorageKey(gradeClass, dayPeriod),
     21 		null,
     22 	);
     23 };
     24 
     25 export default useMySubject;