
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@devup-api/hookform
Advanced tools
Type-safe form components for devup-api with react-hook-form integration and automatic Zod validation.
npm install @devup-api/hookform @devup-api/fetch react-hook-form zod
useFormContextimport { createApi } from '@devup-api/fetch'
import { ApiForm, useFormContext } from '@devup-api/hookform'
const api = createApi('https://api.example.com')
// Form fields component using form context
function FormFields() {
const { register, formState: { errors, isSubmitting } } = useFormContext()
return (
<>
<input {...register('name')} placeholder="Name" />
{errors.name && <span>{errors.name.message}</span>}
<input {...register('email')} placeholder="Email" type="email" />
{errors.email && <span>{errors.email.message}</span>}
<button type="submit" disabled={isSubmitting}>
{isSubmitting ? 'Submitting...' : 'Submit'}
</button>
</>
)
}
// Main form component
function CreateUserForm() {
return (
<ApiForm
api={api}
method="post"
path="createUser" // operationId or path like '/users'
onSuccess={(data) => {
console.log('User created:', data)
}}
onError={(error) => {
console.error('Failed:', error)
}}
>
<FormFields />
</ApiForm>
)
}
<ApiForm
api={api}
method="put"
path="/users/{id}"
requestOptions={{ params: { id: '123' } }}
defaultValues={{
name: 'John Doe',
email: 'john@example.com'
}}
onSuccess={(data) => console.log('Updated:', data)}
>
<FormFields />
</ApiForm>
<ApiForm
api={api}
method="post"
path="createUser"
mode="onChange" // Validate on every change
onValidationError={(errors) => {
console.log('Validation failed:', errors)
}}
onSuccess={(data) => console.log('Created:', data)}
>
<FormFields />
</ApiForm>
<ApiForm
api={api}
method="post"
path="createUser"
resetOnSuccess={true}
onSuccess={(data) => console.log('Created:', data)}
>
<FormFields />
</ApiForm>
<ApiForm
api={api}
method="post"
path="createUser"
formProps={{
className: 'my-form',
id: 'create-user-form'
}}
onSuccess={(data) => console.log('Created:', data)}
>
<FormFields />
</ApiForm>
| Prop | Type | Description |
|---|---|---|
api | DevupApi | The API client instance from @devup-api/fetch |
method | 'post' | 'put' | 'patch' | 'delete' | HTTP method for form submission |
path | string | API path or operationId |
openapi | string | Server name for multi-server setups (default: 'openapi.json') |
requestOptions | object | Additional request options (params, query, headers) |
onSuccess | (data) => void | Called when API request succeeds |
onError | (error) => void | Called when API request fails |
onValidationError | (errors) => void | Called when form validation fails |
children | ReactNode | Form content |
defaultValues | object | Default values for form fields |
mode | 'onSubmit' | 'onBlur' | 'onChange' | 'onTouched' | 'all' | Validation mode (default: 'onSubmit') |
formOptions | UseFormProps | Additional react-hook-form options |
formProps | FormHTMLAttributes | HTML form element props |
resetOnSuccess | boolean | Reset form after successful submission (default: false) |
Children components can access form context using react-hook-form's useFormContext:
import { useFormContext } from '@devup-api/hookform'
function FormField({ name }: { name: string }) {
const { register, formState: { errors } } = useFormContext()
return (
<div>
<input {...register(name)} />
{errors[name] && <span>{errors[name].message}</span>}
</div>
)
}
The ApiForm component automatically uses Zod schemas generated from your OpenAPI spec:
path and method, the component looks up the corresponding request body schema@hookform/resolvers/zod for validationAll props are fully typed based on your OpenAPI schema:
path is typed to only accept valid paths for the specified methodrequestOptions types match the endpoint's params/query/headersonSuccess receives the typed response dataonError receives the typed error responsedefaultValues must match the request body schemaFor convenience, the following are re-exported from react-hook-form:
useFormContextuseWatchuseFieldArrayuseControllerControllerApache 2.0
FAQs
Unknown package
The npm package @devup-api/hookform receives a total of 12 weekly downloads. As such, @devup-api/hookform popularity was classified as not popular.
We found that @devup-api/hookform demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.