# react-wechat-provider

> ``` import { Provider as WP } from 'react-wechat-provider'

Latest version **1.0.3** (published 2020-08-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-wechat-provider
pnpm add react-wechat-provider
yarn add react-wechat-provider
bun add react-wechat-provider
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-08-25 |
| First published | 2018-01-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 192.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | postor |

## Links

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

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [@babel/preset-react](https://npm.io/package/@babel/preset-react.md) ^7.10.4

## Recent versions

- 1.0.3 (latest) — 2020-08-25
- 1.0.2 — 2018-01-11
- 1.0.1 — 2018-01-11
- 1.0.0 — 2018-01-11

## README

# react-wechat-provider

## usage | 使用

### Provider

```
import { Provider as WP } from 'react-wechat-provider'

export default () => (<div>
  <WP config={getConfig} success={(wx)=>console.log(wx)} error={(err) => alert('error')} debug={true}>
    <div>
      <h1>test WechatProvider</h1>
      <Example />
    </div>
  </WP>
</div>)
```

[refer ./example/pages/index.js for more detail | 更多](./example/pages/index.js)

### connect

```
import { Component } from 'react'
import { connect } from 'react-wechat-provider'

class Example extends Component {
  render() {
    const { isWxready, isWechat, wx } = this.props

    const data = JSON.stringify({
      isWxready,
      isWechat,
    })

    return (<div>
      <p>{data}</p>
      {isWxready && (<p>
        <button onClick={() => {
          wx.closeWindow()
        }}>close window through SDK</button>
      </p>)}
    </div>)
  }
}

export default connect(Example)
```

[refer ./example/components/Example.js for more detail | 更多](./example/components/Example.js)


## run example

.babelrc will cause conflict so move example someplace else

```
mv example ../
cd ../example
yarn
mv config-example.json config.json
# fill your wechat appid secret .etc | 填写微信appid secret等
vi config.json
yarn dev
```

then visit http://localhost:3000 | 然后访问 http://localhost:3000 

then bind a domain | 然后绑定一个域名

then add domain to your wechat safe domain | 然后添加这个域名到微信后台的安全域名

then visit http://domain:3000 in your wechat | 然后微信访问 http://domain:3000

![page](./page.png)

![share](./share.png)

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