# react-mc-render

> react-mc-render

Latest version **1.1.0-alpha.18** (published 2021-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-mc-render
pnpm add react-mc-render
yarn add react-mc-render
bun add react-mc-render
```

## 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.0-alpha.18 |
| Published | 2021-12-03 |
| First published | 2020-04-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | xiaoshuang.li |
| Maintainers | xiaoshuang |
| Keywords | react |

## Links

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

## Dependencies (2)

- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## 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

- 1.1.0-alpha.18 (latest) — 2021-12-03
- 1.1.0-alpha.17 — 2021-12-01
- 1.1.0-alpha.16 — 2021-11-05
- 1.1.0-alpha.15 — 2021-10-18
- 1.1.0-alpha.14 — 2021-08-16
- 1.1.0-alpha.13 — 2021-08-04
- 1.1.0-alpha.12 — 2021-08-03
- 1.1.0-alpha.10 — 2021-07-29
- 1.1.0-alpha.9 — 2021-07-27
- 1.1.0-alpha.8 — 2021-07-27
- 1.1.0-alpha.7 — 2021-07-27
- 1.1.0-alpha.5 — 2021-07-26
- 1.1.0-alpha.4 — 2021-07-26
- 1.1.0-alpha.2 — 2021-07-26
- 1.0.8 — 2021-04-22
- … 17 more at https://npm.io/package/react-mc-render/versions

## README

# `react-mc-render`

Render the ```value``` we got.

## Installation

Using [npm](https://www.npmjs.com/):

    $ npm install --save react-mc-render

## Usage

```jsx
import React from 'react';

import ReactMCRender from 'react-mc-render';

/**
 * In this case,
 * will only render some "div" with different id.
 * Because we have not set up options.getComponentClass.
 */
const App = (props = {}) => {
  const { value = {} } = props;

  return (
    <ReactMCRender value={value} />
  );
};

export default App;
```

## props.value: object

The ```value``` you can render.

[Detail for value](https://github.com/xiaoshuangLi/react-mc#concept);

## props.options: object

The parameters you need to configure to render ```value``` in the way you want.

```jsx
const options = {
  getComponentClass: (component = {}) => 'div',
  getComponentRenderDependencies: (component = {}) => [],
  render: (ComponentClass, component = {}) => (props = {}, ref) => {
    return (
      <ComponentClass ref={ref} {...props} />
    );
  },
};
```

#### options.getComponentClass

Return the ```ComponentClass``` to render the ```component```.

```jsx
import React from 'react';

const Input = React.forwardRef((props, ref) => {
  return 
});

const Text = React.forwardRef((props, ref) => {
  return <span ref={ref} {...props} />
});

const Img = React.forwardRef((props, ref) => {
  return <img ref={ref} {...props} />
});

const getComponentClass = (component = {}) => {
  const { name } = component;

  switch (name) {
    case 'input':
      return Input;
    case 'span':
      return Text;
    case 'img':
      return Img;
    default:
      return 'div';
  }
};
```

#### options.getComponentRenderDependencies

Ruturn the dependencies for rendering.The ```ComponentClass``` will render only if dependencies change.```component``` and ```relation``` are already in the dependencies by default.

```jsx
const selectedComponent = {};
const { id: selectedComponentId } = selectedComponent;

// render when select the component
const getComponentRenderDependencies = (component = {}) => {
  const { id: componentId } = component;

  const selected = selectedComponentId === componentId;

  return [selected];
};
```

#### options.render

The final touch to render ```component``` correctly.This function is useful when you want to do something nasty.

```jsx
import { findDOMNode } from 'react-dom';

/**
 * ComponentClass: elementType, is what getComponentClass return
 * props: object, base on component.props and relation.
 */
const render = (ComponentClass, component = {}) => (props = {}, ref) => {
  const { current } = ref;
  const dom = findDOMNode(current);

  return (
    <ComponentClass ref={ref} {...props} />
  );
};
```

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