react-tangle
TypeScript icon, indicating that this package has built-in type declarations

3.0.5 • Public • Published

react-tangle

codecov npm version

A simple react app state management library.

Motivation

Use it to make it quickly provide shared state for your React projects and ideal for rapid application prototyping. Reduces most boilerplates and just share state between components directly.

Example

  1. TodoMvC

Basic

  npm install react-tangle

Then you need to render your app enclosed in a TangleProvider.

 
return (
  <TangleProvider initialValue={{}}>
    <App/>
  </TangleProvider>
)
 

To use a shared state between 2 components, use the useTangledState hook

  import { useTangledState } from 'react-tangle'
 
  // here App
  const TodosList = () => {
    const [todos] = useTangledState('todos', [])
 
    return (
      <div>
        { todos.map(todo => (<div key={todo}>{todo}</div>))}
      </div>
    )
  }
 
  const AddTodo = () => {
    const [todos, setTodos] = useTangledState('todos', [])
 
    const onAdd = (todo: string) => {
      setTodos((current) => {
        return current.concat([todo]) // todos under TodosList should update
      })
    }
    return (
      <div>
        <AddTodoComponent onAdd={onAdd}/>
      </div>
    )
  }
 
 

License

MIT

Others

Thanks to @tmcw for providing the react-tangle npm package

Dependencies (0)

    Dev Dependencies (18)

    Package Sidebar

    Install

    npm i react-tangle

    Weekly Downloads

    38

    Version

    3.0.5

    License

    none

    Unpacked Size

    9.25 kB

    Total Files

    15

    Last publish

    Collaborators

    • tmcw
    • wmira