Skip to content
Discussion options

You must be logged in to vote

I just abstracted the form into its own component that accepted props to prepopulate values or display errors if they exist. As well as a boolean to toggle editing vs creating text.

import { useEffect, useState } from "react";
import { Form, useTransition } from "remix";
import { PostInput } from "~/post";

interface PostFormProps {
  values?: PostInput;
  errors: { [key in keyof PostInput]?: boolean };
  editing?: boolean;
}

export const PostForm = ({ errors, values, editing }: PostFormProps) => {
  const transition = useTransition();

  return (
    <Form method="post" key={values?.slug}>
      <p>
        <label>
          Post Title: {errors?.title ? <em>Title is required</em> : null}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sandeepkumar03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants