Zefty
Zefty
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Zefty on 7/19/2024 in #questions
Using fetch with typescript leads to Unsafe assignment of an `any` value.
No description
3 replies
TTCTheo's Typesafe Cult
Created by Zefty on 7/2/2024 in #questions
How do I reset form fields through a server action / server component?
I have a form where there is a simple input field and a button. After clicking the submit button, the form submits and data is sent through a server action. How to I reset the form field while maintaining the component as a server component? I have see many solutions online where we would convert it into a client component and userefs/hooks etc to reset the form fields. Is there a way to do this through the server action / server component?
export default async function SubmitPlaylist() {
async function submitPlaylist(formData: FormData) {
'use server';

await api.playlist.submitPlaylist();

redirect("/playlist");
}

return (
<form
id="submit-playlist-form"
action={submitPlaylist}
>
<div className="grid w-full items-center gap-4">
<div className="flex flex-col space-y-1.5">
<Label htmlFor="playlistUrl">Playlist</Label>
<Input id="playlistUrl" name="playlistUrl" placeholder="Spotify playlist link" />
</div>
</div>
</form>
)
}
export default async function SubmitPlaylist() {
async function submitPlaylist(formData: FormData) {
'use server';

await api.playlist.submitPlaylist();

redirect("/playlist");
}

return (
<form
id="submit-playlist-form"
action={submitPlaylist}
>
<div className="grid w-full items-center gap-4">
<div className="flex flex-col space-y-1.5">
<Label htmlFor="playlistUrl">Playlist</Label>
<Input id="playlistUrl" name="playlistUrl" placeholder="Spotify playlist link" />
</div>
</div>
</form>
)
}
3 replies
TTCTheo's Typesafe Cult
Created by Zefty on 6/30/2024 in #questions
Anyone familiar with useOptimistic hook to explain how it works???
Hey everyone, im currently using the t3 stack with Next.js app router and have trying to get the useOptimistic hook alongside a server action working So far I have managed to get this all working correctly with one caveat: I have to put "revalidatePath("<url here>")" as the very last line in my server action in order for the hook to work. If I don't do this, the UI flashes for a brief moment and resets back to the "old state" (in my case the button flashes from filled back to unfilled)
4 replies
DTDrizzle Team
Created by Zefty on 6/24/2024 in #help
Postgres store procedure definition in schema file
Hey all, has anyone know of a way to create definitions of stored procedures in the schema file (similar to that of views)? I saw something in this discussion but not quite sure how to implement the schema in my schema.ts file. https://github.com/drizzle-team/drizzle-orm/issues/168
1 replies