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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rhc/form

v0.0.5

Published

react hook component for form

Downloads

3

Readme

@rhc/form

简单、易用、可扩展的表单组件。

Build And Deploy codecov npm version npm

简介

基于 React Hooks 的表单组件。 了解更多

Github

能力

  • 结构化(视图即数据结构,满足复杂数据结构,支持表单项嵌套)
  • 插件化(支持自定义表单项渲染容器和表单项校验渲染容器)
  • 状态灵活(支持跨层级、跨组件、跨表单取值设值)
  • 数据驱动(支持跨层级、跨组件监听表单某项变化,并触发当前组件渲染)
  • 最小粒度渲染(提高在复杂表单场景下表单页面性能)
  • 简单易用(提供简洁实用的 API,如:取值(get)、设值(set)、移除(remove)、重置表单(reset)、表单校验(validate) API 等)

安装

npm install @rhc/form

示例

// example.tsx
import React from "react";
import Form, { useForm } from "@rhc/form";

const Example = () => {
  const form = useForm("live-demo");
  const handleSubmit = () => {
    form
      .validate()
      .then((value) => {
        let formValue = form.getValues();
        console.log("formValue", formValue);
      })
      .catch((err) => {
        console.log("formErr", err);
      });
  };
  return (
    <Form form={form}>
      <Form.Item
        name="name"
        label="姓名"
        required
        rules={(value) => {
          if (value) {
            return Promise.resolve();
          } else {
            return Promise.reject(new Error("请输入姓名"));
          }
        }}
      >
        <Input placeholder="请输入姓名" />
      </Form.Item>
      <Form.Item name="age" label="年龄">
        <Input type="number" placeholder="请输入年龄" />
      </Form.Item>
      <button type="button" onClick={handleSubmit}>
        submit
      </button>
    </Form>
  );
};

export default Example;

interface InputProps {
  value?: string;
  onChange?: (v: string) => void;
  type?: "text" | "number";
  placeholder?: string;
  disabled?: boolean;
}
// Input 组件
const Input: FC<InputProps> = (props) => {
  const { value = "", onChange, type = "text", placeholder, disabled } = props;

  const handleChange = (e: { target: { value: string } }) => {
    onChange && onChange(e.target.value);
  };

  return (
    <input
      disabled={disabled}
      type={type}
      value={value}
      onChange={handleChange}
      placeholder={placeholder}
    />
  );
};