Skip to content

Commit

Permalink
added useState to handle inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
RbAvci committed May 17, 2024
1 parent 055bd82 commit 34f9123
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions client/src/NewVideoForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useState } from "react";

import "./NewVideoForm.css";
const NewVideoForm = () => {
const [title, setTitle] = useState("");
const [src, setSrc] = useState("");

const handleSubmit = (e) => {
e.preventDefault();

Expand All @@ -9,10 +14,7 @@ const NewVideoForm = () => {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
title: e.target.title.value,
src: e.target.src.value,
}),
body: JSON.stringify({ title, src }),
})
.then((response) => response.json())
.then((data) => {
Expand All @@ -28,12 +30,24 @@ const NewVideoForm = () => {
<h2>Add New Video</h2>
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="title">Video Title:</label>
<input type="text" id="title" required />
<label htmlFor="title">Video Title: </label>
<input
type="text"
id="title"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
/>
</div>
<div>
<label htmlFor="src">Video url:</label>
<input type="url" id="src" required />
<label htmlFor="src">Video URL: </label>
<input
type="url"
id="src"
value={src}
onChange={(e) => setSrc(e.target.value)}
required
/>
</div>
<button type="submit">Submit</button>
</form>
Expand Down

0 comments on commit 34f9123

Please sign in to comment.