npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-form-next

v3.0.6

Published

react form ui component

Downloads

15

Readme

Form 表单组件

该表单组件主要解决了 form 表单相关的3个问题:

  • 各个元素如何排版布局
  • 各个值的自动管理
  • 表单验证(onChange 即时校验及提交的全部校验)

具体设计思想:React form 表单组件的解决方案

该组件主要提供了两个组件:

  • 表单组件 Form
  • 表单项组件 FormItemFormItem 可独立于 Form 组件使用,
  • 基于表单项的高阶组件 FormItemContext,与表单组件 Form 配合使用。

Demo 可查看:

安装与引用

npm install react-form-next --save-dev
import { Form, FormContext, FormItem } from "react-form-next";
// 默认不带样式,如果需要样式,请导入
import "react-form-next/index.css";

FormItem 组件

首先,整个表单可以分为多个表单项。而一个表单项从结构上可能会涉及到 6 个部分:label、前缀、表单元素(或自定义的表单元素)、后缀、说明文字,校验态。大概如下图:

这样我们就可以根据这些封装成一个 FormItem 组件,其属性大概如下:

具体各个属性的设计可以查看上面的设计思想:React form 表单组件的解决方案

具体使用可看 FormItem 组件 demo 的源码

Form 组件

Form 组件主要是使用 react 的 context 思想,将校验相关的三个属性valuecheckMsgonChange 通过 Form 组件传递给高级组件 FormItemContext

而具体的检验将使用 schema-typed 这个数据建模及数据验证工具。(该工具设计得非常赞,简直是眼前一亮,具体可以查看文档。)

注:context 使用了 react 16.3.x 引入的新的context api,使用之前请确保升级了 react 到 react 16.3.x 或以上。