
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@panter/react-forms
Advanced tools
You can install Prisma Inputs using npm or yarn:
yarn add @panter/react-forms
This package is not transpiled jet.
If you want to use it with next js you need to add this to your next.config.js:
const nextConfig = {
transpilePackages: ["@panter/react-forms"]
...
}
The useUploadFieldArray custom hook is designed to integrate with React Hook Form's useFieldArray for managing the state of file uploads within a dynamic form array. This hook simplifies handling file uploads, including tracking upload progress, updating file information in the form, and removing files. It's particularly useful when you have a form that allows users to upload multiple files, and you need to keep the form state in sync with those uploads.
The hook accepts an object with the following properties:
##Â Returns The hook returns an object containing several properties and functions for managing file uploads:
This hook is particularly useful in scenarios where you need to upload files as part of a form and maintain the state of those uploads within a dynamic array. It abstracts away the complexity of handling file uploads, progress tracking, and state updates, making it easier to integrate file uploads into your forms with React Hook Form.
Here's a simplified example of how you might use useUploadFieldArray in a component:
const MyFormComponent = () => {
const { control } = useForm();
const { fields, uploadFiles, updateFile, remove } = useUploadFieldArray({
name: 'myFiles',
control,
assetToInput: ({ file }) => ({
// Transform the uploaded file into the format expected by your form
id: file.id,
url: file.url,
// Add any additional transformation logic here
}),
uploader: ({ file }) => upload(file),
});
return (
<form>
{fields.map((field, index) => (
<div key={field.id}>
{/* Render your file input or preview component here */}
<button type="button" onClick={() => remove(index)}>
Remove
</button>
</div>
))}
<input
type="file"
multiple
onChange={(e) => uploadFiles(e.target.files)}
/>
</form>
);
};
createGraphqlFormModalThe createGraphqlFormModal utility function simplifies creating forms that interact with GraphQL mutations. It provides a reusable way to handle form modals, with type safety powered by TypeScript.
The createGraphqlFormModal pattern uses a factory approach to create type-safe form modal hooks. This two-step process is essential for several reasons:
createGraphqlFormModalWe'll demonstrate how to use the createGraphqlFormModal utility to handle a simple mutation using a modal form.
import { graphql } from '@apollo/client';
import { TypedDocumentNode } from '@apollo/client';
const AssignToProjectMutation = graphql(/* GraphQL */ `
mutation AssignToProject($input: SplitFromOriginBcForProjectInput!) {
assignBCToProject(input: $input) {
id
quantity
quantityUnit
}
}
`) as TypedDocumentNode<
{ assignBCToProject: { id: string; quantity: number; quantityUnit: string } },
{ input: SplitFromOriginBcForProjectInput }
>;
type SplitFromOriginBcForProjectModel = {
projectId: { id: string };
quantity: number;
quantityUnit: string;
};
createGraphqlFormModalThe factory pattern used in createGraphqlFormModal serves a crucial purpose for TypeScript type inference and safety. Let's break down why this approach is valuable:
import { createGraphqlFormModal } from '@panter/react-forms';
const useAssignToProjectModal =
createGraphqlFormModal<SplitFromOriginBcForProjectInput>();
import React, { useCallback } from 'react';
import { GraphqlFormModal } from '@panter/react-forms';
import { useTranslation } from 'react-i18next';
import { SendOutlined } from '@ant-design/icons';
export const useAssignToProject = () => {
const { t } = useTranslation();
const [handleOpenModal, formModalProps] = useAssignToProjectModal({
mutation: AssignToProjectMutation,
title: t('Assign Building Component to Project'),
defaultValues: () => ({
projectId: 'default-project-id',
quantity: 5,
quantityUnit: 'pcs',
}),
modelToInput: async (formModel) => ({
input: { ...formModel, projectId: formModel.projectId.id },
}),
renderForm: ({ schemaForm }) => (
<div>
<input {...schemaForm.register('projectId')} placeholder="Project ID" />
<input
type="number"
{...schemaForm.register('quantity')}
placeholder="Quantity"
/>
<input
{...schemaForm.register('quantityUnit')}
placeholder="Quantity Unit"
/>
</div>
),
});
return { handleOpenModal, formModalProps };
};
import React from 'react';
import { useAssignToProject } from './useAssignToProject';
import { GraphqlFormModal } from '@panter/react-forms-ant';
export const AssignToProjectButton = () => {
const { openModal, formModalProps } = useAssignToProject();
return (
<div>
<button onClick={openModal}>Assign to Project</button>
<GraphqlFormModal {...formModalProps} />
</div>
);
};
If you also need to run a query before opening the modal, use the createGraphqlFormModalWithQuery utility.
const useAssignToProjectWithQuery = createGraphqlFormModalWithQuery<SplitFromOriginBcForProjectInput>();
const [handleOpenModal, formModalProps] = useAssignToProjectWithQuery({
mutation: AssignToProjectMutation,
query: OneProjectQuery,
title: 'Assign to Project with Query',
defaultValues: () => ({
projectId: { id: 'project-id' },
quantity: 10,
quantityUnit: 'pcs',
}),
modelToInput: async (formModel) => ({
input: { ...formModel, projectId: formModel.projectId.id },
}),
renderForm: ({ schemaForm }) => (
<div>
<input {...schemaForm.register('project.id')} placeholder="Project ID" />
<input type="number" {...schemaForm.register('quantity')} placeholder="Quantity" />
<input {...schemaForm.register('quantityUnit')} placeholder="Quantity Unit" />
</div>
),
});
FAQs
## Installation
We found that @panter/react-forms demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.