Next.js Discord

Discord Forum

Reactivity through Client and Server Component

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
I'm trying to react when the New Social button is clicked and change locally (I'll save it in the database once the user press the Save button) and I thought I'd be able to do that by creating a client component with some useStates that propagates to the parent page (RSC), but I'm not sure if that's even possible.

<div className="grid gap-2">
  {/* This is a client component */}
  <Socials socials={user.socials} />
  <button
    className="..."
    type="submit"
  >
    <div className="flex p-4">
      <PlusIcon /><h2>New Social</h2>
    </div>
  </button>
</div>

5 Replies

Polar bearOP
If I wasn't very clear I can provide more information
Polar bearOP
I thought about rendering the entire form inside a Client Component then passing a server action from the parent page to save the form! Seems like a promising one.
New Guinea Singing Dog
You could save all the buttons in an array then map over them, rendering out a social component for each one
When a user adds one, it appends it to the array, and then renders a new social component
Then yeah could use the server action to actually write changes to the DB