百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rhf-stepform

> 前端框架
开源

使用 React Hook Form、Yup、TypeScript 和 Zustand 构建的步骤表单

195 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用 React Hook Form、Yup、TypeScript 和 Zustand 构建的步骤表单

React-Hook-Form Stepform

Code to observe:

  • https://github.com/theodorusclarence/rhf-stepform/tree/main/pages/form, form pages
  • https://github.com/theodorusclarence/rhf-stepform/blob/main/store/useFormStore.tsx, where form data is stored
  • https://github.com/theodorusclarence/rhf-stepform/blob/main/lib/yup.ts, yup schema
  • https://github.com/theodorusclarence/rhf-stepform/blob/main/types.ts, form type declaration
  • https://github.com/theodorusclarence/rhf-stepform/tree/main/components/Forms, form components

Key Points

Each time submitting, data is stored in FormStore

const onSubmit = (data: StepOneData) => {
  setData({ step: 1, data });
  router.push('/form/step-2');
};

The stored data will be used as a default value on revisit

const { stepOne, setData } = useFormStore();

const methods = useForm({
  mode: 'onTouched',
  resolver: yupResolver(stepOneSchema),
  defaultValues: stepOne || {},
});

Upload Form

The tricky part lies in Upload Form. The data that is originally stored by the input is File object, but if we store it in zustand, it will be transformed into regular object. This will cause an error when we invoke the URL.createObjectURL(file) for the FilePreview.

So we need to invoke it while we get the original File, and store the URL as a new property. In that way, we only invoke it once, and just use the blob url for revisit.

const acceptedFilesPreview = acceptedFiles.map(
  (file: FileWithPreview) =>
    Object.assign(file, {
      preview: URL.createObjectURL(file),
    })
);

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Theodorus Clarence

Muhammad Rizqi Tsani

This project follows the all-contributors specification. Contributions of any kind welcome!

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptnextjsreact-hook-formtypescriptyup

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架