Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SicDoRak
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
2023_2_WebPromgramming_8
SicDoRak
Commits
a9884814
Commit
a9884814
authored
1 year ago
by
Jaeyong Lee
Browse files
Options
Downloads
Patches
Plain Diff
Add PostWrite.js
parent
f5494995
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/PostWrite.js
+75
-0
75 additions, 0 deletions
frontend/src/PostWrite.js
with
75 additions
and
0 deletions
frontend/src/PostWrite.js
0 → 100644
+
75
−
0
View file @
a9884814
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment