Monthly.js 1.01 KB
Newer Older
1
import React, { useState, useEffect } from 'react';
Choi Ga Young's avatar
Choi Ga Young committed
2
import Calendar from './components/Calendar';
Choi Ga Young's avatar
Choi Ga Young committed
3
import calApi from './db/calendarInfo.api';
Choi Ga Young's avatar
Choi Ga Young committed
4
import { useFocusEffect } from '@react-navigation/native';
Choi Ga Young's avatar
Choi Ga Young committed
5

Choi Ga Young's avatar
Choi Ga Young committed
6
const Montly = ({ navigation }) => {
7
8
9
10
11
12
13
  const date = new Date();
  const [year, setYear] = useState(date.getFullYear());
  const [month, setMonth] = useState(date.getMonth());
  const todayM = date.getMonth();
  const todayY = date.getFullYear();
  const [totalM, setTotalM] = useState([]);

Choi Ga Young's avatar
Choi Ga Young committed
14
15
  const getData = async () => {
    try {
16
17
      const resDBdata = await calApi.getFullData({ year: year, month: month })
      setTotalM(resDBdata)
Choi Ga Young's avatar
Choi Ga Young committed
18
19
20
21
22
23
    } catch (error) {
      console.log('error in getData', error)
    }
  }
  useEffect(() => {
    getData()
24
  }, [month])
Choi Ga Young's avatar
Choi Ga Young committed
25
26
27
28
29
30

  useFocusEffect(
    React.useCallback(() => {
      getData()
    }, [])
  );
Choi Ga Young's avatar
Choi Ga Young committed
31
  return (
32
    <Calendar navigation={navigation} MData={totalM} year={year} setYear={setYear} month={month} setMonth={setMonth} todayM={todayM} todayY={todayY} />
Choi Ga Young's avatar
Choi Ga Young committed
33
34
  )
}
Choi Ga Young's avatar
Choi Ga Young committed
35

Choi Ga Young's avatar
Choi Ga Young committed
36
export default Montly;