New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@reform/api

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reform/api

Pure React Forms API based on new Context API

  • 0.9.22
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

@reform/api

Simple and powerful React forms API. Write forms faster, more simple and clear.

Install

npm install @reform/api

*This package requires react@16.6+.

Usage

Main usage

TextInput.tsx

import * as React from "react";
import {Component} from "@reform/api";

export class TextInput extends Component {
    protected onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        this.update(e.target.value);
    }

    protected get className() {
        if (!this.valid) {
            return "is-not-valid";
        }

        if (this.changed) {
            return "is-changed";
        }

        return "";
    }

    public render() {
        return <input {...this.getDefaultProps()}/>;
    }

    protected getDefaultProps() {
        return {
            className: this.className,
            onChange: this.onChange,
            value: this.value,
            name: this.name,
            type: "text",
        }
    }
}

Form.tsx

import * as React from "react";
import {Component, Store} from "@reform/api";
import {TextInput} from "./TextInput.tsx";

interface ISource {
  name: string;
}

export default () => {
    const defaultSource: ISource = {
        name: "Hello",
    };
    
    // will trigger 
    const onChange = (store: Store<ISource>) => {
        console.log("changed", store);
    }
        
    // will trigger on enter
    const onSubmit = (data: ISource, store: Store<ISource>) => {
        console.log("submit", data);
        return true;
    }
    
    return (
        <Form defaultSource={defaultSource}
              onSubmit={console.log}
              onChange={console.log}>
            <p><TextInput name={"name"}/></p>
            <p><button>Submit</button></p>
        </Form>
    );
};

Examples

Setup npm run bootstrap and play npm run doc:play.

Keywords

FAQs

Package last updated on 30 Apr 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc