react-tangle
A Simple State Management Library in React
Last updated 3 months ago by wmira .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-tangle 
SYNC missed versions from official npm registry.

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

Current Tags

  • 3.0.5                                ...           latest (3 months ago)

18 Versions

  • 3.0.5                                ...           3 months ago
  • 3.0.4                                ...           3 months ago
  • 3.0.3                                ...           3 months ago
  • 3.0.2                                ...           3 months ago
  • 3.0.1                                ...           3 months ago
  • 3.0.0                                ...           3 months ago
  • 2.2.0                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.2                                ...           6 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.3.0                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 1
Last Month 19
Dependencies (0)
None
Dev Dependencies (18)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |