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

rocket-useform

v0.1.0

Published

Rich useForm hooks. Make complex forms easily.

Downloads

77

Readme

Rocket useForm

WARNING: library in alpha version

Rocket useForm is a rich React library based on useRef. It's an easy-to-use solution to build big and complex forms.

Installation

npm i rocket-useform

Getting started


const data = {
	name: 'john doe'
}

const schema = Schema({
	name: textField({required:true, validation: (name)=>name.length > 3})
})

const MyForm = () => {

	const form = useForm(data, schema)

	const handleSave = () => {

		if(form.checkForm()){
			console.log(form.toJSON())
			form.setModified(false)
		} else {
			console.warn('Il y a des champs incorrects !')
		}
	}

	return (
		<div>
			{form.modified ? 'Modifié':''}
			<input {...matchInput(form.get('name))}>
			<button onClick={()=>handleSave()}>SAVE</button>
		</div>
	)
}

Main concepts

Schema based

const schema = Schema({
  name: textField()
})

Possible fields types:

  • textField
  • numberField
  • booleanField
  • arrayField

Each field schema can take a param argument, where you will define validation rules, defaultValue and so on:

const schema = Schema({
  email: textField({
    validators: [Validator.TEmail]
  })
})

See docs for more details

Path system

const cityField = form.get('user.address.city')

Can also be splitted :

const addressField = form.get('user.address')
const cityField = addressField.get('city')

Get parent :

const cityField = form.get('user.address.city')
const addressField = addressField.get('parent')

From root :

const cityField = form.get('user.address.city')
const nameField = addressField.get('root.user.name')

Node

Form is a tree of Nodes reachable through path:

const rootNode = form.get('')
const userNode = rootNode.get('user')

Stateless

Rocket useForm is stateless for performance. It means that data flow is unidirectional.

  • You need sur match input with defaultValue :
	<input
		defaultValue={form.get('name').value}
		onChange={e => form.get('name').update(e.target.value)}
	>

But don't worry ! You can force refresh this way :

	<input
		defaultValue={form.get('name').value}
		onChange={e => form.get('name').update(e.target.value, true)}
	>

update function take a boolean as second argument : forceRefresh

Schema

Field

  • Text field
const schema = {
  name: textField()
}
  • Number field
const schema = {
  name: numberField()
}
  • Boolean field
const schema = {
  name: booleanField()
}

Object

Array

const schema = {
  users: arrayField({
    name: textField()
  })
}

Params