From a9884814b136655d0c81b498f343e8250aa2c1bf Mon Sep 17 00:00:00 2001
From: LEE <dlwodyd7613@ajou.ac.kr>
Date: Tue, 28 Nov 2023 00:00:12 +0900
Subject: [PATCH] Add PostWrite.js

---
 frontend/src/PostWrite.js | 75 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 frontend/src/PostWrite.js

diff --git a/frontend/src/PostWrite.js b/frontend/src/PostWrite.js
new file mode 100644
index 00000000..5765fb41
--- /dev/null
+++ b/frontend/src/PostWrite.js
@@ -0,0 +1,75 @@
+import React, { useState } from 'react';
+import { useNavigate } from 'react-router-dom';
+
+
+function PostWrite(){
+
+    // const [title, setTitle] = useState('');
+    // const [content, setContent] = useState('');
+    // const [imageUrls, setImageUrls] = useState([]);
+
+    const [inputs, setInputs] = useState({
+        title: "",
+        content: "",
+        imageUrls: ""
+    });
+
+    const {title, content, imageUrls} = inputs; // 비구조화 할당;
+
+    const handleSubmit= async (event) => {
+        event.preventDefault();
+        try {
+            const response = await fetch('http://post/:id', {
+                method: 'POST',
+                headers: {
+                    'Content-Type': 'application/json',
+                },
+                body: JSON.stringify(),
+            });
+
+            if (!response.ok) {
+                throw new Error(`HTTP error! status: ${response.status}`);
+            }
+
+            const data = await response.json();
+            console.log('Post created successfully:', data);
+        }
+        catch (error){
+            console.log('Error during post creation:', error);
+        }
+    }
+
+    const onChange = (e) => {
+        const {value, name} = e.target;
+        setInputs({
+            ...inputs,
+            [name]: value
+        });
+    }
+
+    return(
+        <form onSubmit={handleSubmit}>
+            <div>
+                <label>제목</label>
+                <input
+                    type="text"
+                    value={title}
+                    onChange={onChange}
+                    required
+                />
+            </div>
+            <div>
+                <label>Content</label>
+                <textarea
+                value={content}
+                onChange={onChange}
+                />
+            </div>
+        </form>
+    )
+
+
+}
+
+
+export default PostWrite;
\ No newline at end of file
-- 
GitLab