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

dynamic-list-react

v1.0.8

Published

No-modes input management for dynamic React forms.

Downloads

6

Readme

dynamic-list-react

Inspired by Larry Tesler's work, this package contains a react component to render a list of input items that can be added to, updated and removed from without switching between edit and view modes and without any buttons (optionally, a delete button can be shown for each item).

Installation

npm install dynamic-list-react

Usage

Basic Example

Basic Example Illustration

import React from 'react';
import { DynamicList, type HandleInputChange } from 'dynamic-list-react';

export function ExampleDynamicList() {
	const data = getCurrentData();
	const defaultItem = { name: '' };

	const updateKeyValue = (_id: string, key: string, value: any) => {
		const currentData = getCurrentData();
		const itemToUpdate = currentData.find(item => item._id === _id);
		if (itemToUpdate) {
			itemToUpdate[key] = value;
			setData(currentData);
		}
	}

	const removeItem = (_id: string) => {
		const currentData = getCurrentData();
		setData(currentData.filter(item => item._id !== _id));
	}

	const addItem = (item: ItemType) => {
		const currentData = getCurrentData();
		setData(currentData.concat(item));
	}

	const InputComponent = (item: ItemType, handleInputChange: HandleInputChange<ItemType>) => (
		<div key={item._id}>
			<input
				placeholder="Name"
				value={item.name}
				onChange={e => handleInputChange(item._id, 'name', e.target.value)}
			/>
		</div>
	);

	return (
		<DynamicList<ItemType>
			renderComponent={InputComponent}
			dataProp={data}
			addItem={addItem}
			updateKeyValue={updateKeyValue}
			removeItem={removeItem}
			defaultItem={defaultItem}
		/>
	);
}

function getCurrentData() {
		return JSON.parse(localStorage.getItem('storageKey') || '[]') as ItemType[];
	}

function setData(data: ItemType[]) {
	localStorage.setItem('storageKey', JSON.stringify(data));
}

type ItemType = Record<string, any>;

Advanced Example

Advanced Example Illustration

import React from 'react'
import { DynamicList, type HandleDelete, type HandleInputChange } from 'dynamic-list-react'

export function ExampleDynamicList() {
	const data = getCurrentData()
	const defaultItem = {
		firstName: '',
		lastName: '',
		score: '',
	}

	const updateKeyValue = (_id: string, key: string, value: any) => {
		const currentData = getCurrentData()
		const itemToUpdate = currentData.find((item) => item._id === _id)
		if (itemToUpdate) {
			itemToUpdate[key] = value
			setData(currentData)
		}
	}

	const removeItem = (_id: string) => {
		const currentData = getCurrentData()
		setData(currentData.filter((item) => item._id !== _id))
	}

	const addItem = (item: ItemType) => {
		const currentData = getCurrentData()
		setData(currentData.concat(item))
	}

	const InputComponent = (
		item: ItemType,
		handleInputChange: HandleInputChange<ItemType>,
		handleDelete: HandleDelete,
		isLastItem: boolean,
		idx: number
	) => (
		<div key={item._id}>
			<p>Item {idx + 1}</p>
			<input
				placeholder='First Name'
				value={item.firstName}
				onChange={(e) => handleInputChange(item._id, 'firstName', e.target.value)}
			/>
			<input
				placeholder='Last Name'
				value={item.lastName}
				onChange={(e) => handleInputChange(item._id, 'lastName', e.target.value)}
			/>
			<input
				placeholder='Score'
				value={item.score}
				onChange={(e) => handleInputChange(item._id, 'score', e.target.value)}
			/>
			{isLastItem ? null : <button onClick={() => handleDelete(item._id)}>Delete</button>}
		</div>
	)

	return (
		<DynamicList<ItemType>
			renderComponent={InputComponent}
			dataProp={data}
			addItem={addItem}
			updateKeyValue={updateKeyValue}
			removeItem={removeItem}
			defaultItem={defaultItem}
			getRandomId={getRandomId}
		/>
	)
}

function getCurrentData() {
	return JSON.parse(localStorage.getItem('storageKey') || '[]') as ItemType[]
}

function setData(data: ItemType[]) {
	localStorage.setItem('storageKey', JSON.stringify(data))
}

function getRandomId() {
	// e.g. crypto.randomUUID() or uuidv4()
	return Date.now().toString()
}

type ItemType = Record<string, any>

Larry Tesler: No Modes

One of Mr Tesler's firmest beliefs was that computer systems should stop using "modes", which were common in software design at the time. Modes allow users to switch between functions on software and apps but make computers both time-consuming and complicated. So strong was this belief that Mr Tesler's website was called "nomodes.com", his Twitter handle was "@nomodes", and even his car's registration plate was "No Modes".

Source: https://www.bbc.com/news/world-us-canada-51567695