Skip to content

Commit d89aa89

Browse files
update document adding cdn links
1 parent a754ed8 commit d89aa89

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

README.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# string-to-react-component
1+
# string-to-react-component
22

33
Create React component from string
44

@@ -30,16 +30,17 @@ or
3030
$ yarn add string-to-react-component
3131
```
3232

33-
Also you should install `@babel/standalone` package because `string-to-react-component` has a peer dependency of `@babel/standalone`
33+
`string-to-react-component` has a peer dependency of `@babel/standalone`, then you should install `@babel/standalone` package :
3434

3535
```js
3636
$ npm install @babel/standalone --save
37+
```
3738

38-
or
39-
40-
//load `@babel/standalone` in the browser
39+
### CDN Links
4140

41+
```js
4242
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
43+
<script src="https://unpkg.com/[email protected]/dist/stringToReactComponent.umd.min.js"></script>
4344
```
4445

4546
## Basic Example
@@ -124,38 +125,38 @@ function App() {
124125
- not required
125126
- See the full option list [here](https://babeljs.io/docs/en/options)
126127
- examples :
127-
* using source map :
128-
```js
129-
<StringToReactComponent babelOptions={{filename: 'counter.js', sourceMaps: 'inline'}}>
130-
{`(props)=>{
131-
const {useState}=React;
132-
const [counter,setCounter]=useState(0);
133-
const increase=()=>{
134-
setCounter(counter+1);
135-
};
136-
return (<>
137-
<button onClick={increase}>+</button>
138-
<span>{'counter : '+ counter}</span>
139-
</>);
140-
}`}
141-
</StringToReactComponent>
142-
```
143-
* using typescript :
144-
```js
145-
<StringToReactComponent babelOptions={{ filename: 'counter.ts',presets: [["typescript", { allExtensions: true, isTSX: true }]] }}>
146-
{`()=>{
147-
const [counter,setCounter]=React.useState<number>(0);
148-
const increase=()=>{
149-
setCounter(counter+1);
150-
};
151-
return (<>
152-
<button onClick={increase}>+</button>
153-
<span>{'counter : '+ counter}</span>
154-
</>);
155-
}`}
156-
</StringToReactComponent>
157-
```
158-
128+
- using source map :
129+
```js
130+
<StringToReactComponent babelOptions={{filename: 'counter.js', sourceMaps: 'inline'}}>
131+
{`(props)=>{
132+
const {useState}=React;
133+
const [counter,setCounter]=useState(0);
134+
const increase=()=>{
135+
setCounter(counter+1);
136+
};
137+
return (<>
138+
<button onClick={increase}>+</button>
139+
<span>{'counter : '+ counter}</span>
140+
</>);
141+
}`}
142+
</StringToReactComponent>
143+
```
144+
- using typescript :
145+
```js
146+
<StringToReactComponent
147+
babelOptions={{filename: 'counter.ts', presets: [['typescript', {allExtensions: true, isTSX: true}]]}}>
148+
{`()=>{
149+
const [counter,setCounter]=React.useState<number>(0);
150+
const increase=()=>{
151+
setCounter(counter+1);
152+
};
153+
return (<>
154+
<button onClick={increase}>+</button>
155+
<span>{'counter : '+ counter}</span>
156+
</>);
157+
}`}
158+
</StringToReactComponent>
159+
```
159160

160161
## Caveats
161162

0 commit comments

Comments
 (0)