1.0.0 • Published 4 years ago

@bytesoftio/use-list v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@bytesoftio/use-list

Installation

yarn add @bytesoftio/use-list or npm install @bytesoftio/use-list

Table of contents

Description

This package provides a React integration for @bytesoftio/list.

useList

Use this helper to hook up a store inside a React component.

import React from "react"
import {createList} from "@bytesoftio/list"
import {useList} from "@bytesoftio/use-list"

const globalList = createList(["apple", "oranges"])

const Component = () => {
  // create a new list
  const list1 = useList(["apples"])

  // create a new list through an initializer / factory function
  const list2 = useList(globalList) 
  
  const addItem = () => list1.add("oranges")
  const addItemGlobal = () => list2.add("tomatos")
 
  return (
    <div>
      <button onClick={addItem}>local items: {list1.get().join(",")}</button>    
      <button onClick={addItemGlobal}>global items: {globalList.get().join(",")}</button>    
    </div>
  )
}