Monthly.js 1.02 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 { useIsFocused } 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 }) => {
Choi Ga Young's avatar
Choi Ga Young committed
7
8
  const isFocused = useIsFocused();

9
10
11
12
13
14
15
  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
16
17
  const getData = async () => {
    try {
18
19
      const resDBdata = await calApi.getFullData({ year: year, month: month })
      setTotalM(resDBdata)
Choi Ga Young's avatar
Choi Ga Young committed
20
21
22
23
24
25
    } catch (error) {
      console.log('error in getData', error)
    }
  }
  useEffect(() => {
    getData()
26
  }, [month])
Choi Ga Young's avatar
Choi Ga Young committed
27

Choi Ga Young's avatar
Choi Ga Young committed
28
29
30
31
  useEffect(() => {
    getData()
  }, [isFocused])

Choi Ga Young's avatar
Choi Ga Young committed
32
  return (
33
    <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
34
35
  )
}
Choi Ga Young's avatar
Choi Ga Young committed
36

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