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 🙏

© 2026 – Pkg Stats / Ryan Hefner

strooks

v1.2.14

Published

Made with create-react-library

Readme

strooks

A fine collection of Hooks, Components and Utils for your React application

Hooks

useForm()

useForm is the simplest, easiest and most versatile way to manage form state in React applications. It's the form manager that works closest to default HTML behavior so the only requirement is that you use the nameproperty in the form elements, so they will become the keys to your state

import { useRef } from 'react'
import { useForm } from 'strooks'

const MyComponent = () => {
  const formRef = useRef()
  const [formState, update, clear] = useForm(formRef, initialState)

  return <form ref={formRef} onSubmit={onSubmit}></form>
}
No need to:
  • pass values into each input, everything is managed for you - the inputs are immediately filled according to the initial state
  • setting up onChange method for the form or each input unless you want to run realtime validation
  • ev.preventDefault() inside your onSubmit button
  • worry about checked property for radio-buttons or checkboxes
out of the box:

Easy Typing

using the attribute type="number" or data-type="number" the value in the state will always be a number:

<form>
  <input type="text" name="firstName" />
  <input type="number" name="age" />
  <select name="yearsOfExperience" data-type="number">
    {new Array(50).fill(null).map(idx => (
      <option value={idx}>{idx} years</option>
    ))}
  </select>
</form>

results in a state typed like:

{ "firstName": "John", "age": 22, "yearsOfExperience": 15 }

Values as Arrays

whether using a multi-select or a set of checkboxes with the same name, the resulting state will be an array with the values:

<form>
  <select name="cars" multiple>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
  </select>
  <div>
    <h5>Hobbies</h5>
    <label>
      <input name="hobbies" type="checkbox" value="swimming" />
      <span>Swimming</span>
    </label>
    <label>
      <input name="hobbies" type="checkbox" value="running" />
      <span>Running</span>
    </label>
    <label>
      <input name="hobbies" type="checkbox" value="tennis" />
      <span>Tennis</span>
    </label>
  </div>
</form>

the resulting state will be:

{ "cars": ["volvo", "opel"], "hobbies": ["swimming", "tennis"] }

Boolean Fields:

getting a true or false from a checkbox or a pair of radio-buttons can be cumbersome, having to parse the checked property of several elements. With useForm is just a matter of "following the HTML"

  • for checkboxes, not passing a value property, turns the property into true or false
  • for radios, whatever value you pass into it, is going to be stored in the state
<form>
  <input type="checkbox" name="agree" />
  <div>
    <input type="radio" name="useColor" value={true} />
    <input type="radio" name="useColor" value={false} />
    {formState.useColor && (
      <div>
        <input type="radio" name="color" value="blue" />
        <input type="radio" name="color" value="red" />
        <input type="radio" name="color" value="green" />
      </div>
    )}
  </div>
</form>

will result in the state:

{ "agree": true, "useColor": true, "color": "red" }

Nested Fields

It's super easy to create forms with nested fields, take the following example:

<form ref={formRef} onSubmit={onSubmit}>
  <input type="text" name="name" />
  <input type="text" name="address.street" />
  <input type="number" name="address.zipCode" />
  <input type="text" name="address.city" />
</form>

will result in the state:

{ "name": "...", "address": { "street": "...", "zipCode": 12345, "city": "..." } }

Custom Components

a lot of the components we find on NPM won't work out of the box with useForm because they don't mimic the default behavior of HTML form elements but it's very easy to circumvent that, using the update method. For example, we're using a custom Select, that:

  • receives an optionsarray in the form of [{ value, label }]
  • needs to receive the selected value as a prop
  • needs an onChange eventHandler that receives as parameter the whole option object
import { useRef } from 'react'
import { useForm } from 'strooks'
import { CustomSelect } from 'some-ui-library'

const App = () => {
  const formRef = useRef()
  const [formState, update] = useForm(formRef)

  const onSelectChange = (option) => {
    update(state => ({...state, flavor: option.value })
  }
  return (
    <form ref={formRef}>
      <CustomSelect options={options} value={formState.flavor} onChange={onSelectChange} />
    </form>
  )
}

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]

MIT © andrepadez