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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-dynamic-inputs

v1.0.2

Published

Lightweight component for creating dynamic inputs

Readme

React Dynamic Inputs Component

The react-dynamic-inputs component allows you to create a dynamic list of input fields where users can add or remove input items. It is highly customizable with support for a custom layout, input validation, and dynamic item addition/removal.

🌐 Demo

Checkout Demo of react-dynamic-inputs

Properties

| Property | Type | Description | | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | onChange | (values: string[]) => void | A callback function that is triggered when the values in the input fields change. It receives an array of updated values as a parameter. | | children | (inputProps: { handleOnChange: (e: React.ChangeEvent<HTMLInputElement>) => void; defaultValue: string }, removeButtonProps: { handleOnClick: (e: React.MouseEvent<HTMLElement>) => void; disabled: boolean }) => React.ReactElement | A custom render function that allows you to pass custom input fields and remove buttons. The function receives inputProps and removeButtonProps for customization. | | defaultValues | string[] | Give Default Values of the Input(s). If given value count is smaller than defaultItemsCount, no default Value will be given. Useful when component rendering based on condition | | defaultItemsCount | number | The number of input fields to be initially displayed. Default is 2. | | minItems | number | The minimum number of input fields that should be allowed. Default is 0. | | maxItems | number | null | The maximum number of input fields allowed. If set to null, there's no upper limit. | | className | string | A custom CSS class name that will be applied to the root element of the component. | | style | React.CSSProperties | Inline styles that will be applied to the root element of the component. | | inputWrapperStyle | React.CSSProperties | Inline styles that will be applied to each input wrapper element. | | addButtonLabel | React.ReactNode | null | The label for the "Add More" button. Default is "Add More". | | customAddButton | React.ReactElement<any, any> | null | A custom React element to render as the "Add More" button. If provided, this will replace the default button. |

Example

import React, { useState } from "react";
import DynamicInputs from "react-dynamic-inputs";

const App = () => {
    const [inputValues, setInputValues] = useState([]);

    const handleValuesChange = (values) => {
        setInputValues(values);
    };

    return (
        <div>
            <h1>Dynamic Inputs Example</h1>

            <DynamicInputs
                onChange={handleValuesChange}
                defaultItems={3}
                minItems={1}
                maxItems={5}
                addButtonLabel="Add More Fields"
                className="my-custom-class"
            />

            <div>
                <h2>Current Input Values:</h2>
                <pre>{JSON.stringify(inputValues, null, 2)}</pre>
            </div>
        </div>
    );
};

export default App;

Key Notes:

  • onChange: This will update the parent component with the current values whenever any input field is updated.
  • defaultItems: You can specify how many input fields should be present when the component is first rendered.
  • minItems & maxItems: These properties ensure that the number of inputs stays within the allowed limits.
  • customAddButton: If you want to replace the default "Add More" button, pass in your custom button as a React element.

Custom Rendering

You can also pass a custom render function as the children prop, which allows you to have full control over how each input and remove button are rendered.

Example of using children:

import React, { useState } from "react";
import DynamicInputs from "react-dynamic-inputs";

const App = () => {
    const [inputValues, setInputValues] = useState([]);

    const handleValuesChange = (values) => {
        setInputValues(values);
    };

    return (
        <div>
            <h1>Dynamic Input Example</h1>

            <DynamicInputs
                onChange={handleValuesChange}
                defaultItems={2}
                minItems={1}
                maxItems={5}
            >
                {(inputProps, removeButtonProps) => (
                    <div className="custom-input-wrapper">
                        <input {...inputProps} className="custom-input" />
                        <button
                            {...removeButtonProps}
                            className="custom-remove-button"
                        >
                            Remove
                        </button>
                    </div>
                )}
            </DynamicInputs>
        </div>
    );
};

export default App;

In this example, the children function receives inputProps (for the input element) and removeButtonProps (for the remove button), allowing you to customize their appearance and behavior.

Example

There is also a useable Example in example folder. Feel free to check it out!