# react-mlsdata

> A simple declarative data component for React

Latest version **0.5.11** (published 2017-09-22) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.11 |
| Published | 2017-09-22 |
| First published | 2017-05-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mark Flavin |
| Maintainers | psyne |
| Keywords | react, react-component |

## Links

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

## Dependencies (2)

- [react-odata](https://npm.io/package/react-odata.md) ^4.5.2
- [whatwg-fetch](https://npm.io/package/whatwg-fetch.md) ^2.0.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.11 (latest) — 2017-09-22
- 0.5.10 — 2017-08-28
- 0.5.9 — 2017-08-09
- 0.5.8 — 2017-06-22
- 0.5.7 — 2017-05-31
- 0.5.6 — 2017-05-24
- 0.5.5 — 2017-05-15
- 0.5.4 — 2017-05-15
- 0.5.3 — 2017-05-10
- 0.5.2 — 2017-05-09
- 0.5.1 — 2017-05-09
- 0.4.6 — 2017-05-04
- 0.4.5 — 2017-05-04
- 0.4.4 — 2017-05-03
- 0.4.3 — 2017-05-03
- … 12 more at https://npm.io/package/react-mlsdata/versions

## README

# React MLSData Component

A react component to simplify the use of MLS Data from the MLSListings Odata Service within an Application.

## Install 
```
npm install --save react-mlsdata
```

## Options
* collection - the collection you want to access example www, vow, public etc...
* resource - the resource you are trying to access examples property, agent, media etc..
* token - the authorization token from the mlslistings identity provider
* link - an odata link returned within the collection request

## Media
If you are accessing an item in the media resource there is some options you can pass to optimize your request
* ListingKeyNumeric - the integer value of the media resource for the listing you want to display it must be a number 
  example ListingKeyNumeric = {this.ListingKey} || ListingKeyNumeric = {1234456}
* MemberKeyNumeric - the integer value of the media resource for the agent you want to display it must be a number
* MediaType = defaults to Photo. You can pass thumbnail if you want a smaller image for display in a list

## Geography
To access geography information 

## Stats
If you are accessing statistics for a particular widget (Market Trends, Key PerformanceIndicators, Year to Year), you can pass the following options to optimize your request
* collection - member, office, markettrends, KPI, year-to-year
* select - Data to be selected for stats
* filter - criteria for selection



## Media Examples

### Property Thumbnail
```js
<MLSMedia MediaType="Thumbnail" ListingKeyNumeric={265403} limit="1" token={authtoken}>
  {({ loading, error, data }) => (
    <div>
      {error && 
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
      }
      {data &&
        <div>
          <Values data={data} />

          { !data.value.length &&
            <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
          }

          { data.value.length !== 0 &&
            <img src={data.value[0].MediaURL} alt="Thumbnail"/>
          }
        </div>
      }
    </div>
  )}
</MLSMedia>
```

### Agent Photo
```js
<MLSMedia MediaType="Thumbnail" MemberKeyNumeric={150591} limit="1" token={authtoken}>
  {({ loading, error, data }) => (
    <div>
      {error && 
        <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
      }
      {data &&
        <div>
          <Values data={data} />

          { !data.value.length &&
            <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Image%20Not%20Found&w=150&h=150" alt="Missing Image" />
          }

          { data.value.length !== 0 &&
            <img src={data.value[0].MediaURL} alt="Thumbnail"/>
          }
        </div>
      }
    </div>
  )}
</MLSMedia>
```


## MLSCount
A simplified interface for retrieving the count for any query. Simply pass the same query and filters to MLSCount component. 
It will in a declarative form return a count for the query which can the be used to display number of results or to build 
a pagination element 

## MLSCount Example

```js

class Pagination extends Component {
  render() {
    console.log(this.props.data["@odata.count"]);
    return <div />;
  }
}

<MLSCount collection="Property" token={authtoken}>
  {({ data }) => (
    <div>
      { data &&
      <Pagination data={data} />
    }
    </div>
  )}
</MLSCount>
```

## Usage
### Import
```js
import MLSData from 'react-mlsdata';
```
### Basic
```js
import React from "react";
import MLSData from "react-mlsdata";

class Values extends React.Component {
  render() {
    console.log(this.props.data);

    return <div />;
  }
}

class Listings extends React.Component {
  render() {
    const { listings } = this.props;

    var listingCollection = listings.map(listing => (
      <li key={Math.floor(Math.random() * Date.now()) + 1}>
        {listing.ListingId}
      </li>
    ));

    return <ul>{listingCollection}</ul>;
  }
}

class Count extends React.Component {
  render() {
    return (
      <h3>
        <strong>
          {this.props.data.length} Listings Retrieved
        </strong>
      </h3>
    );
  }
}

const tempToken = "your bearer token";

const App = () => (
  <div>
    <MLSData collection="Property" token={tempToken}>
      {({ loading, error, data }) => (
        <div>

          {loading && <h2>{`${loading}`}</h2>}

          {error && <h2>{error.message}</h2>}

          {data &&
            <div>

              <Values data={data} />
              <Count data={data.value}/>

              <Listings listings={data.value} />

            </div>
          }

        </div>
      )}

    </MLSData>
  </div>
);

export default App;

``` 

### Fetch Callback

You can pass functions to the onChange prop to run as the fetch is being run. Loading states, Data, Response and etc will be available to a handler function.

```
class App extends Component {
  constructor() {
    super()
    this.handleResponse = this.handleResponse.bind(this)
  }

  handleResponse(response){
    console.info("info response:", response);
  }

  render() {
    return (
      <div>
        <MLSData collection="Property" token={authtoken} onChange={this.handleResponse} />
      </div>
    );
  }
}
```

- See [react-odata](https://github.com/techniq/react-odata) for additional options

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