Skip to content
Snippets Groups Projects
Commit a9884814 authored by Jaeyong Lee's avatar Jaeyong Lee
Browse files

Add PostWrite.js

parent f5494995
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment