Best Practices
In order to ensure that zsa
is used to its full potential, we've collected a few "best" practices. We hope to grow this list as more developers discover new ways of using zsa
.
-
Naming multiple calls:
- If you need to call multiple server actions, you can name the resulting destructured array based on the action's functionality.
-
Simple error messages:
- When handling errors from server actions, throw the error message directly as a string from the server side:
- On the client side, you can access the error message using
err.data
and display it using a toast or any other preferred method:
-
Creating actions from procedures:
- When creating server actions from procedures, create the procedure first and then chain the
createServerAction()
method: - Instead of:
- When creating server actions from procedures, create the procedure first and then chain the
By following these best practices, you can ensure a cleaner and more maintainable codebase when using zsa
.