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

react-bureaucrat

v1.1.1

Published

React Bureaucrat is a component library for building forms

Readme

React Bureaucrat

A component library for react applications that simplifies building forms.

Installing

npm install react-bureaucrat

Props

Form

| Name | Required | Type | Default | Usage | | --------------------------- | :-------: | -------- | ------- | ------- |
| id | [x] | String |
| onSubmit | [x] | Function | | Called on form submission, if no fields have errors. Receives the form's current state as its only argument. Form state will be an object {"field-name-1": "value of field 1", "field-name-2", "value of field 2" ...} | | alwaysSubmit | | Boolean | false | Forces onSubmit prop function to be called on form submission regardless of errors | onFailedSubmit | | Function | | Called on form submission, if any fields have errors. | onPropogatedFailedSubmit | | Function | | Called on form submission once for every field with errors. Each call receives a field's name and current errors as its arguments.

Children

The Form component can accept either react elements

  <Form>
    <Field>
      {...}
    </Field>
    <div />
    <Field>
      {...}
    <Field>
  </Form>

or a function as children. The function will receive as an argument the count of submission attempts. You can use this to call any error handlers in the inputs that might normally require the user to interact with that input.

<Form>
{submissionAttempts => (
  <Field>
    {...}
  </Field>
  <div />
  <Field>
    {...}
  <Field>
)}
</Form>

Field

| Name | Required | Type | Default | Usage | | --------------------------- | :-------: | -------- | ------- | ------- | | defaultValue | | | | Gives the field a starting value | errors | | Array | [] | Each element in the array must be an object with a _handle key and a message key. The _handle key's value will be a function which takes as its argument the field's value. If that function evaluates to true, the message key's value will be passed to the field's children. | name | [x] | String | | Is the fields unique identifier. It is used as a key in the form state | onFailedSubmit | | Function | Called on form submission if the field has any current errors. Receives those errors as it's argument.

Children

The Field component accepts a function as its child. It receives as its argument an object containing the current errors, an onChange function, and the Field's value.

  <Field>
  {({ currentErrors, onChange, value }) => (
      <div>
        <input
          onChange={onChange}
          value={value}
          {...other props}
        {currentErrors.length > 0 && <span>{currentErrors[0]}</span>}
        />
      </div>
    )
  }
  </Field>

Examples

<!-- file: my-form.js  -->
import React from 'react';
import { Form, Field } from 'react-bureaucrat';
import MyInput from './my-input.js'

const MyForm = ({ onSubmit }) => (
  <Form>
    id="unique-id"
    onSubmit={ onSubmit }
    onFailedSubmit={() => alert('At least one field has an error')}
    onPropogatedFailedSubmit={(fieldName, fieldErrors) => { console.log(`${name}: ${fieldErrors}`) }}
    {submissionAttempts =>
      <Field
        name="firstName"
        errors={
          [
            { _handle: v => !v, message: "Can't be blank" },
            { _handle: v => v.length < 5, message: "Must be at least 5 characters" }
          ]
        }
        onFailedSubmit={currentErrors => { console.log(`My first error: ${currentErrors[0]}`) }}
        >
        {({currentErrors, onChange, value})
          <MyInput
            currentErrors={currentErrors}
            onChange={onChange}
            value={value}
            submissionAttempts={submissionAttempts}
          />
        }
      <Field
        name="lastName"
        errors={
          [
            { _handle: v => !v, message: "Can't be blank" },
          ]
        }
        >
        {({currentErrors, onChange, value})
          <MyInput
          currentErrors={currentErrors}
          onChange={onChange}
          value={value}
          submissionAttempts={submissionAttempts}
          />
        }
      </Field>
    }
  </Form>
);

<!-- file: my-input.js  -->
import React from 'react';

export default class MyInput extends React.Component {
  constructor() {
    super();
    this.state = {
      showErrors: false
    }
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.submissionAttempts > this.props.submissionAttempts) {
      this.setState({ showErrors: true });
    }
  }

  render() {
    return (
      <div>
        <input
          onFocus={() => { this.setState({ showErrors: false }) }}
          onBlur={() => { this.setState({ showErrors: true }) }}
          onChange={this.props.onChange}
          value={this.props.value}
          {...other props}
        {this.state.showErrors && currentErrors.length > 0 && <span>{currentErrors[0]}</span>}
        />
      </div>
    )
  }
}

License

This project is licensed under the ISC License