더북(TheBook)

여기까지 작성하고 배열에 내용이 잘 추가되는지 확인해볼까요?

FeedsScreen에서 useContext를 사용해 LogContext의 값을 받아온 뒤, logs 배열을 콘솔에 출력해보세요.

screens/FeedsScreen.js

import React, {useContext} from 'react';
import {StyleSheet, View} from 'react-native';
import FloatingWriteButton from '../components/FloatingWriteButton';
import LogContext from '../contexts/LogContext';

function FeedsScreen() {
  const {logs} = useContext(LogContext);
  console.log(JSON.stringify(logs, null, 2));

(...)

JSON.stringify()를 사용할 때 두 번째와 세 번째 파라미터를 이와 같이 설정해주면 객체나 배열을 출력할 때 공백과 새 줄을 포함해 보기 좋게 출력해줍니다. 이제 새 항목을 작성하고 터미널을 확인해보세요. 다음과 같이 잘 출력되나요?

[
  {
    "id": "2e9db794-e9e1-40a2-a8f8-5ba8100ee2fe",
    "title": "Hello",
    "body": "Hello World!",
    "date": "2021-08-23T20:20:16.235Z"
  }
]

이렇게 객체에 네 가지 값이 모두 정상적으로 들어갔는지 확인해주세요. 잘 출력이 됐다면, console. log 코드는 제거해주세요.

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.