5.0.1 • Published 5 months ago

replicache-react v5.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

replicache-react

npm version

Build your UI using subscribe() (or useSubscribe in React). Whenever the data in Replicache changes — either due to changes in this tab, another tab, or on the server — the affected UI automatically updates. Replicache only refires subscriptions when the query results have actually changed, eliminating wasteful re-renders.

API

function useSubscribe

React hook that allows you monitor replicache changes

ParameterTypeDescription
repReplicacheReplicache instance that is being monitored
query(tx: ReadTransaction) => PromiseQuery that retrieves data to be watched
defRdefault value returned until initial run of query completes
depsArray = []OPTIONAL: list of dependencies, query will be rerun when any of these change

Usage

example of useSubscribe in todo app that is watching a specific category

const {category} = props
const todos = useSubscribe(
    replicache, 
    tx => tx.scan({prefix: `/todo/${category}`}).values().toArray(), 
    [], 
    [category]
);

return (
  <ul>
    {todos.map(t => (
      <li>{t.title}</li>
    ))}
  </ul>
);
5.0.1

5 months ago

5.0.0

5 months ago

4.0.1

6 months ago

4.0.0

6 months ago

3.1.0

8 months ago

3.0.0-beta.0

11 months ago

3.0.0

9 months ago

2.11.0

1 year ago

2.10.1

1 year ago

2.10.0

2 years ago

2.9.0

2 years ago

2.8.0

2 years ago

2.7.0

2 years ago

2.6.0

2 years ago

2.3.0

3 years ago

2.5.0

2 years ago

2.4.0

3 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0-beta.1

3 years ago

1.0.4

3 years ago

2.0.0

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago