Skip to content

Commit c611e0b

Browse files
initial commit
1 parent 3765e1c commit c611e0b

15 files changed

+34408
-0
lines changed

.babelrc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const output = process.env.BABEL_OUTPUT;
4+
const requirePolyfills = process.env.INCLUDE_POLYFILLS;
5+
const modules = output == null ? false : output;
6+
const options = {
7+
presets: [['@babel/env', {loose: true, modules}], '@babel/react'],
8+
plugins: ['@babel/plugin-transform-react-jsx'],
9+
env: {
10+
test: {
11+
// extra configuration for process.env.NODE_ENV === 'test'
12+
presets: ['@babel/env'], // overwrite env-config from above with transpiled module syntax
13+
},
14+
},
15+
};
16+
if (requirePolyfills) {
17+
options.plugins.push(['@babel/plugin-transform-runtime', {corejs: 3}]);
18+
}
19+
module.exports = options;

.eslintrc.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"es6": true,
6+
"node": true,
7+
"jest": true
8+
},
9+
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:prettier/recommended"],
10+
"settings": {
11+
"react": {
12+
"version": "detect"
13+
}
14+
},
15+
"parser": "@babel/eslint-parser",
16+
"parserOptions": {
17+
"ecmaFeatures": {
18+
"jsx": true
19+
},
20+
"ecmaVersion": 12,
21+
"sourceType": "module",
22+
"allowImportExportEverywhere": false
23+
},
24+
"plugins": ["eslint-plugin-react", "eslint-plugin-prettier"],
25+
"rules": {
26+
"prettier/prettier": [
27+
"error",
28+
{
29+
"endOfLine": "auto"
30+
}
31+
]
32+
}
33+
}

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ide
2+
/.vscode
3+
4+
# dependencies
5+
/node_modules
6+
example/node_modules
7+
/.pnp
8+
.pnp.js
9+
10+
# testing
11+
/coverage
12+
13+
# production
14+
/build
15+
/lib
16+
/dist
17+
18+
# demo
19+
/demo
20+
21+
# misc
22+
.DS_Store
23+
.env.local
24+
.env.development.local
25+
.env.test.local
26+
.env.production.local
27+
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*

.npmignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ide
2+
/.vscode
3+
4+
# dependencies
5+
/node_modules
6+
/.pnp
7+
.pnp.js
8+
9+
# production
10+
webpack*
11+
rollup*
12+
.babelrc.js
13+
14+
#demo
15+
/example
16+
index.html
17+
/demo
18+
19+
# testing
20+
/coverage
21+
22+
# misc
23+
.DS_Store
24+
.env.local
25+
.env.development.local
26+
.env.test.local
27+
.env.production.local
28+
29+
npm-debug.log*
30+
yarn-debug.log*
31+
yarn-error.log*

.prettierignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ide
2+
/.vscode
3+
4+
# dependencies
5+
/node_modules
6+
example/node_modules
7+
/.pnp
8+
.pnp.js
9+
10+
# testing
11+
/coverage
12+
13+
# production
14+
/build
15+
/lib
16+
/dist
17+
18+
# demo
19+
/demo
20+
21+
# misc
22+
.DS_Store
23+
.env.local
24+
.env.development.local
25+
.env.test.local
26+
.env.production.local
27+
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*

.prettierrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": false,
4+
"jsxBracketSameLine": true,
5+
"printWidth": 120,
6+
"semi": true,
7+
"singleQuote": true,
8+
"tabWidth": 2,
9+
"trailingComma": "all",
10+
"useTabs": false,
11+
"proseWrap": "never"
12+
}

CHANGELOG.md

Whitespace-only changes.

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
11
# string-to-react-component
2+
23
Create React component from string
4+
5+
> _Support react >= `v16.8.0`_
6+
7+
## Table of Contents
8+
9+
<!-- toc -->
10+
11+
- [Installation](#installation)
12+
- [Basic Example](#basic-example)
13+
- [Using Unknown Elements](#using-unknown-elements)
14+
- [Test](#test)
15+
- [License](#license)
16+
17+
<!-- tocstop -->
18+
19+
## Installation
20+
21+
```js
22+
$ npm install string-to-react-component --save
23+
```
24+
25+
Also You need to load `@babel/standalone` in the browser :
26+
27+
```js
28+
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
29+
```
30+
31+
## Basic Example
32+
33+
```js
34+
import React from 'react';
35+
import StringToReactComponent from 'string-to-react-component';
36+
function App() {
37+
return (
38+
<StringToReactComponent>
39+
{`(props)=>{
40+
const {useState}=React;
41+
const [counter,setCounter]=useState(0);
42+
const increase=()=>{
43+
setCounter(counter+1);
44+
};
45+
return (<>
46+
<button onClick={increase}>+</button>
47+
<span>{'counter : '+ counter}</span>
48+
</>);
49+
}`}
50+
</StringToReactComponent>
51+
);
52+
}
53+
```
54+
55+
## Using Unknown Elements
56+
57+
```js
58+
import React from 'react';
59+
import StringToReactComponent from 'string-to-react-component';
60+
function MyComponent() {
61+
return <p>My Component</p>;
62+
}
63+
function App() {
64+
return (
65+
<StringToReactComponent MyComponent={MyComponent}>
66+
{`(props)=>{
67+
const {MyComponent}=props;
68+
return (<MyComponent/>);
69+
}`}
70+
</StringToReactComponent>
71+
);
72+
}
73+
```
74+
75+
## Test
76+
77+
```js
78+
$ npm run test
79+
```
80+
81+
## License
82+
83+
MIT

0 commit comments

Comments
 (0)