useList

React hooks for the @corets/list package.

Source code is hosted on GitHub

yarn add @corets/use-list

This is a React integration for this package:

List

useList()

Use observable lists inside React components:

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

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

const Example = () => {
  const list1 = useList(["apples", "oranges"])
  const list2 = useList(() => createList(["apples", "oranges"]))
  const list3 = useList(globalList)
  // alternative syntax
  const [list, setList] = useList(globalList).use()
  
  const addItem = () => list1.add("tomatoes")
  
  return (
    <div>
      <button onClick={addItem}>Items: {list1.get().join(",")}</button>
    </div>
  )
}

Last updated