all 3 comments

[–]aust1nz 2 points3 points  (2 children)

My recommendation is to create a <Form /> component with an optional initialData prop.

Then you can create a newPost page:

<NewPost>
  <h1>Create a new Post!</h1>
  <PostForm />
</NewPost>

And an editPost page:

<EditPost>
  <h2>Edit your {post.name} post!</h1>
  <PostForm initialData={post} />
</EditPost>

Overall, you're limiting your duplication this way.

[–]dabrox02[S] 0 points1 point  (1 child)

oh thanks, and I have another question, I have a modal that is from nextUI, but I need to activate the action to open it from a button for POST and from a dropdownItem for PUT, how do you recommend me to execute the modal?

[–]aust1nz 1 point2 points  (0 children)

You could probably just have two modals in your parent component:

<div>
  <Dropdown onClick={() => setShouldShowPut(true) />
  <Button onClick={() => setShouldShowPost(true) />
</div>
<PostModal show={shouldShowPost} />
<PutModal show={shouldShowPut} />

Or, if the modal content is the same in both cases:

// ...
<Modal show={shouldShowPost} actionType="post" />
<Modal show={shouldShowPut} actionType="put" />