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

react-demos

v0.0.13

Published

plug and play React components to show off your backend tech by implementing a small set of methods!

Downloads

27

Readme

React Demos

plug and play React components to show off your backend tech by implementing a small set of methods! Done in TypeScript because I like React + TypeScript. Use this as an easy demo to show off your backend integrations. (e.g. React + Firebase, React + AWS Amplify, React + Node/Express/Mongo, etc.)

goes without saying - none of these are meant for production!

Installation

npm i react-demos

Chat Example

import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { Chat, useChatLocalState } from 'react-demos'

const App = () => {
  const {
    currentUser,
    sendMessage,
    loginUser,
    logoutUser,
    messages,
    usersOnline,
  } = useChatLocalState()
  // // To implement:
  //   currentUser: User | null;
  //   usersOnline: User[];
  //   messages: Message[];
  // /** set currentUser and add them to usersOnline */
  // async function loginUser(name: string) {}
  // /** add to messages by also adding the currentUser */
  // async function sendMessage(text: string) {}
  // /** (optional) unset currentUser and remove from usersOnline */
  // async function logOutUser(id: string) {}
  return (
    <div>
      <Chat
        {...{
          currentUser,
          sendMessage,
          loginUser,
          logoutUser,
          messages,
          usersOnline,
        }}
      />
    </div>
  )
}

Here are the schemas of the 2 models used:

export type User = {
  id: string
  name: string
  isOnline: boolean
}
export type Message = { user: string; text: string }
type User @model {
  id: ID!
  name: String
  isOnline: Boolean
}

type Message @model {
  id: ID!
  user: String
  text: String
}

Todo Example

TodoMVC with a clean React implementation (no Redux).

Live Demo: react-todomvc.netlify.app

image

Usage

The core of this package is a <Todos> component that takes 5 props:

  • todos: TodoType[]: an array of TodoType objects
  • addNewTodo: (value: string) => Promise<void>: callback for adding a new todo
  • updateTodo: (modifiedTodo: PartialTodoType) => Promise<void>: update the value or completion state of a Todo by its id
  • deleteTodo?: (id: string) => Promise<void>: optional callback for deleting a todo by ID
  • clearCompletedTodos?: () => void: optional callback for clearing completed todos (if omitted, the corresponding button won't show)
  • todosTitle?: string: optional string - to customize the title shown. defaults to "React-TodoMVC".

For demo purposes, a sample implementation is provided from useTodosLocalState. The intent is that you will swap out these functions for your own as you implement your backend.

import { Todos, useTodosLocalState } from 'react-demos'
import 'react-todomvc/dist/todomvc.css' // for styling

const App = () => {
  // FOR DEMO CREATOR: replace this with your impl!
  const props = useTodosLocalState()
  // // must implement
  // todos: TodoType[]
  // function addNewTodo(value: string): Promise<void>`
  // function updateTodo(modifiedTodo: PartialTodoType): Promise<void>`
  // // optional
  // function deleteTodo(id: string): Promise<void>
  // function clearCompletedTodos(): void
  // todosTitle?: string
  return (
    <div>
      <Todos {...props} />
    </div>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))

If you want something that persists in localstorage, you can use useTodosLocalStorageState instead. It has the same API as useTodosLocalState.

List of Implementations

  • AWS Amplify + AppSync: tbd
  • Firebase: tbd
  • Netlify + FaunaDB: tbd

Acknowledgements

The http://todomvc.com/ project

the todomvc.css was combined from todomvc-app-css and todomvc-common.