-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mikas happy thoughts project #107
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Mika! For upcoming projects I'd love to see you commit a bit more often. See it as your way to save your progress whenever you've implemented a feature or new functionality.
You've split your components into manageable components and you've done a nice job copying the design too. I put some comments throughout your code to think about for upcoming projects.
try { | ||
const res = await fetch(URL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ message: message }), | ||
}); | ||
|
||
if (!res.ok) { | ||
throw new Error(`HTTP error! status: ${res.status}`); | ||
} | ||
|
||
const data = await res.json(); | ||
setThoughts((prevThoughts) => [data, ...prevThoughts]); | ||
setMessage(""); | ||
} catch (error) { | ||
console.error("Error submitting thought:", error); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice with try/catch!
<input | ||
type="text" | ||
value={message} | ||
onChange={(e) => setMessage(e.target.value)} | ||
required | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget labels when working with form elements! And perhaps this should be a textarea since it's a multiline input?
return data; | ||
}; | ||
|
||
export const formatTimeAgo = (timestamp) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! However, does this really belong in an api.js file? 👀
Netlify link
https://mikashappythoughts.netlify.app/