# react-mc-runner

> react-mc-runner

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

## Install

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

## 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 | 3 |
| Unpacked size | 15.6 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-runner
- 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-runner

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [react-mc-render](https://npm.io/package/react-mc-render.md) ^1.1.0-alpha.18

## 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
- … 21 more at https://npm.io/package/react-mc-runner/versions

## README

# `react-mc-runner`

Render the ```value``` we got and bound the events.

## Installation

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

    $ npm install --save react-mc-runner

## Usage

```jsx
import React, { useState } from 'react';

import ReactMCRunner from 'react-mc-runner';

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

  return (
    <ReactMCRunner
      value={value}
      setValue={setValue}
    />
  );
};

export default App;
```

## props.value: object

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

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

## props.setValue: func

Trigger it when ```value``` was changed.The argument is a function which return next ```value```;

```jsx
const App = (props = {}) => {
  const [value = {}, setValue] = useState({});

  // Example: deal with setValue
  const setValueForRunner = (changer) => {
    const nextValue = changer(value);

    setValue(nextValue);
  };

  // Or something native
  const setValueForRunner = setValue;

  return (
    <ReactMCRunner
      value={value}
      setValue={setValueForRunner}
    />
  );
};
```

## 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 = {}) => [],
  getComponentPropsSchema: (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.getComponentPropsSchema

We use [PropsSchema](https://github.com/xiaoshuangLi/react-docgen-props-schema) to define [PropTypes](https://github.com/facebook/prop-types).
For webpack, you can add a plugin to ```babel``` to generate automatically.

[Base on JSONSchema](https://json-schema.org)

[Webpack example](https://github.com/xiaoshuangLi/react-mc/blob/master/examples/webpack.config.js)

#### 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, relation and bound events.
 */
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-runner · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
