![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-zod-safe-action
Advanced tools
React Safe Action: Type-safe action handler for React applications with built-in Zod validation
A type-safe action handler for React applications with built-in form validation using Zod.
npm install react-zod-safe-action
# or
yarn add react-zod-safe-action
# or
pnpm add react-zod-safe-action
import { SafeAction } from "react-zod-safe-action";
import { z } from "zod";
// create a safe action and reuse anywhere
export const actionClient = new SafeAction();
// Define your input schema
const loginSchema = z.object({
email: z.string().email(),
password: z.string().min(8)
});
// Create a safe action
const loginAction = actionClient.schema(loginSchema).action(async (data) => {
// Your login logic here
return { success: true };
});
import { useAction } from "react-zod-safe-action";
function LoginForm() {
const { execute, status, loading } = useAction(loginAction, {
onSuccess: (data) => {
console.log("Login successful", data);
},
onError: ({ error, input }) => {
console.log("Login failed", error);
}
});
const handleSubmit = (e) => {
e.preventDefault();
execute({
email: "user@example.com",
password: "password123"
});
};
return <form onSubmit={handleSubmit}>{/* Your form elements */}</form>;
}
SafeAction
Creates a new safe action with optional schema validation.
const actionClient = new SafeAction();
actionClient.schema(zodSchema).action((data) => Promise<Result>);
useAction
Hook to execute the safe action and manage its state.
const {
execute, // Function to execute the action
status, // 'idle' | 'executing' | 'error' | 'success'
loading, // boolean
reset // Function to reset the state
} = useAction(action, {
onSuccess?: (data: Result) => void,
onError?: (error: {
error: {
validation: Record<string, string>,
request: Record<string, string>
},
input: Input
}) => void
});
react-zod-safe-action provides structured error handling for both validation and request errors:
{
validation: { // Zod validation errors
'field.path': 'error message'
},
request: { // Other runtime errors
'error_key': 'error message'
}
}
MIT
FAQs
React Safe Action: Type-safe action handler for React applications with built-in Zod validation
We found that react-zod-safe-action demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.