# react-datadeps

> Declarative data dependencies for react components

Latest version **1.0.30** (published 2017-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-datadeps
pnpm add react-datadeps
yarn add react-datadeps
bun add react-datadeps
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.30 |
| Published | 2017-08-11 |
| First published | 2017-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rafael Salguero Iturrios |
| Maintainers | rafaelsalguero |

## Links

- npm: https://www.npmjs.com/package/react-datadeps
- Repository: https://github.com/RafaelSalguero/react-datadeps
- Homepage: https://github.com/RafaelSalguero/react-datadeps#readme
- Issues: https://github.com/RafaelSalguero/react-datadeps/issues
- npm.io page: https://npm.io/package/react-datadeps

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^15.5.4
- [keautils](https://npm.io/package/keautils.md) ^1.0.4

## Recent versions

- 1.0.30 (latest) — 2017-08-11
- 1.0.29 — 2017-08-04
- 1.0.28 — 2017-08-04
- 1.0.27 — 2017-07-28
- 1.0.26 — 2017-07-25
- 1.0.25 — 2017-07-25
- 1.0.23 — 2017-07-25
- 1.0.22 — 2017-07-05
- 1.0.21 — 2017-07-04
- 1.0.20 — 2017-07-04
- 1.0.19 — 2017-07-04
- 1.0.18 — 2017-07-04
- 1.0.17 — 2017-07-04
- 1.0.16 — 2017-07-03
- 1.0.15 — 2017-07-03
- … 25 more at https://npm.io/package/react-datadeps/versions

## README

# react-datadeps
## Manage data dependencies with stateless components

### 1.- Create a stateless component
```tsx
interface Props {
    id: string;
    myData: string;
    moreData: string;
    myRefresh: () => void;
}
class MyComponent extends React.Component<Props, {}> {
    render() {
        return <div>
            {this.props.myData}
            {this.props.moreData}
            <button onClick={this.props.myRefresh} >Refresh!</button>
        </div>
    }
}
```

### 2.- `mapPropsToThunks`
```ts
import { mapPropsToThunks, PropDependencies } from "react-datadeps";
import { myService, otherService } from "./myService";

const deps: PropDependencies<Props> = {
    myData: {
        query: async (props) => await myService(props.id), //query can be an async function
        async: true, //true to await the query result
        params: ["id"] //when props.id changes, refresh this query
    },
    moreData: {
        query: async (props) => await otherService(props.myData), //neasted data dependency
        async: true,
        params: ["myData"]
    },
    myRefresh: {
        query: (props, refresh) => () => refresh() //Inner component can fire a data refresh
    }
};

```

### 3.- Consume the component
```jsx
//If id changes, myData and moreData will be refreshed
<MyComponent2 id="42" />
```

---
_Source: https://npm.io/package/react-datadeps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
