最近(2018年以降)の開発では関数ベースのコンポーネントが主流のため、一部を書き換えた。 React App.js import React, { useState, useEffect } from "react"; import Modal from "./components/Modal"; import axios from "axios"; const App = () => { const [topicList, setTopicList] = useState([]); const [modal, setModal] = useState(false); const [activeTopic, setActiveTopic] = useState({ comment: "" }); // コンポーネントがレンダリングされるときに実行する useEffect(() => { refreshList(); }, []); // ページロード const refreshList = () => { axios .get("/api/topics/") .then((res) => setTopicList(res.data)) .catch((err) => console.log(err)); }; const handleSubmit = (topic) => { if (topic.id) { axios .put(`/api/topics/${topic.id}/`, topic) .then(() => refreshList()) .catch((err) => console.log(err)); } else { axios .post("/api/topics/", topic) .then(() => refreshList()) .catch((err) => console.log(err)); } closeModal(); }; const handleDelete = (topic) => { axios .delete(`/api/topics/${topic.id}/`) .then(() => refreshList()); }; const openModal = (topic) => { if (topic.id) { setActiveTopic(topic); } else { setActiveTopic({ comment: ...