7.6.1 WriteHeader에서 날짜 및 시간 보여주기
우선 WriteScreen에서 date 상태를 만들어주세요. 그리고 onSave에서 수정하거나 새로 저장할 때 date 상태를 사용하도록 변경합니다. WriteHeader에는 date와 onChangeDate를 Props로 넣어주세요.
screens/WriteScreen.js
import {useNavigation} from '@react-navigation/native'; import React, {useContext, useState} from 'react'; import {Alert, KeyboardAvoidingView, Platform, StyleSheet} from 'react-native'; import {SafeAreaView} from 'react-native-safe-area-context'; import WriteEditor from '../components/WriteEditor'; import WriteHeader from '../components/WriteHeader'; import LogContext from '../contexts/LogContext'; function ({route}) { const log route.params?.log; const [title, setTitle] (log?.title ''); const [body, setBody] (log?.body ''); const navigation (); const [date, setDate] = useState(log ? new Date(log.date) : new Date()); const {onCreate, onModify, onRemove} (LogContext); ( ) const () => { if (log) { ({ id: log.id, date: date.toISOString(), title, body, }); } else { ({ title, body, date: date.toISOString(), }); } navigation. (); }; return ( <SafeAreaView style={styles.block}> <KeyboardAvoidingView style={styles.avoidingView} behavior={Platform.OS === 'ios' ? 'padding' : undefined}> <WriteHeader onSave={onSave} onAskRemove={onAskRemove} isEditing={!!log} date={date} onChangeDate={setDate} /> <WriteEditor title={title} body={body} onChangeTitle={setTitle} onChangeBody={setBody} /> </KeyboardAvoidingView> </SafeAreaView> ); } ( )