Skip to content
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

Server Action in a loop can't pass data #631

Open
AlbertSabate opened this issue Nov 15, 2024 · 3 comments
Open

Server Action in a loop can't pass data #631

AlbertSabate opened this issue Nov 15, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers

Comments

@AlbertSabate
Copy link
Collaborator

AlbertSabate commented Nov 15, 2024

Is your feature request related to a problem? Please describe.
When you do a loop

{response.data
  .map((booking) => (
    <button onClick={(e) => doSomething(e, booking.id)}>lala</button>
))}

booking.id will throw an error because it does not exist on the client and the server bookind.id will be undefined.

The very unique way to solve this is injecting a data attr and use dataset to retreive the data on the server.

{response.data
  .map((booking) => (
    <button data-lala={booking.id} onClick={doSomething}>lala</button>
))}

// then e.currentTarget.dataset.lala will have the info

This is working and is a valid approach, but maybe we could document this or give a better way to handle this situation.

@AlbertSabate AlbertSabate added documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers labels Nov 15, 2024
@aralroca aralroca added good first issue Good for newcomers and removed good first issue Good for newcomers labels Nov 15, 2024
@aralroca
Copy link
Collaborator

@aralroca
Copy link
Collaborator

btw; improve any kind of documentation is always very welcome as a contribution

@AlbertSabate
Copy link
Collaborator Author

Ohh nice, I saw the commit b66b39b
@aralroca so fast adding docs haha

Let's keep it open for now, maybe someone can improve the examples? If there is no volunteers I'll get more examples there :)

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants