# react-cam

> ![npm](https://img.shields.io/npm/dw/react-cam.svg)

Latest version **1.1.11** (published 2019-11-30) · Apache-2.0 license · 0 weekly downloads

## Install

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

## 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.1.11 |
| Published | 2019-11-30 |
| First published | 2018-07-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 22.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ccwukong |

## Links

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

## Dependencies (4)

- [react](https://npm.io/package/react.md) ^16.8.6
- [react-dom](https://npm.io/package/react-dom.md) ^16.8.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.2
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.7.4

## Recent versions

- 1.1.11 (latest) — 2019-11-30
- 1.1.10 — 2019-11-30
- 1.1.9 — 2019-11-30
- 1.1.7 — 2019-11-30
- 1.1.6 — 2019-11-30
- 1.1.3 — 2019-11-30
- 1.1.2 — 2019-11-30
- 1.1.1 — 2019-11-30
- 1.1.0 — 2019-11-30
- 1.0.6 — 2019-11-30
- 1.0.3 — 2019-11-30
- 1.0.2 — 2019-07-14
- 1.0.1 — 2019-07-14
- 1.0.0 — 2019-07-11
- 0.1.6 — 2018-08-28
- … 15 more at https://npm.io/package/react-cam/versions

## README

# react-cam

![npm](https://img.shields.io/npm/dw/react-cam.svg)

HTML5 Web/Mobile camera for ReactJS

# Installation

## NPM

```console
npm install react-cam
```

## Yarn

```console
yarn add react-cam
```

# How to use it?

## props

| Prop name   | Optional | Default   | Description                                                                    |
| ----------- | -------- | --------- | ------------------------------------------------------------------------------ |
| showFocus   | Yes      | false     | show/hide the blue focus box, basically useless...                             |
| front       | Yes      | false     | true: front camera, false: rear camera                                         |
| capture     | No       | None      | A function to handle base64 string image                                       |
| width       | No       | 480       | Camera pixel width, percentage or absolute value                               |
| height      | No       | 320       | Camera pixel height, percentage or absolute value                              |
| focusWidth  | Yes      | 80%       | Camera focus box width, percentage or absolute value                           |
| focusHeight | Yes      | 50%       | Camera focus box height, percentage or absolute value                          |
| btnColor    | Yes      | '#2acef5' | Set color of the capture button                                                |
| onError     | No       |           | Handles camera error, the error object will be passed as the function argument |

## example

```javascript
import React, { Fragment, useRef } from 'react';
import ReactDOM from 'react-dom';
import { Camera } from 'react-cam';

function capture(imgSrc) {
  console.log(imgSrc);
}

const App = () => {
  const cam = useRef(null);
  return (
    <Fragment>
      <Camera
        showFocus={true}
        front={false}
        capture={capture}
        ref={cam}
        width="80%"
        height="auto"
        focusWidth="80%"
        focusHeight="60%"
        btnColor="white"
      />
      <button onClick={img => cam.current.capture(img)}>Take image</button>
    </Fragment>
  );
};
ReactDOM.render(<App />, document.getElementById('root'));
```

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