Skip to content

Commit 2620426

Browse files
update REQDME.md
1 parent 7c1b40b commit 2620426

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Also You need to load `@babel/standalone` in the browser :
3131
## Basic Example
3232

3333
```js
34-
import React from 'react';
3534
import StringToReactComponent from 'string-to-react-component';
3635
function App() {
3736
return (
@@ -52,14 +51,35 @@ function App() {
5251
}
5352
```
5453

55-
## Using Unknown Elements
54+
### Notes
55+
56+
- The given code inside the string should be a function.
57+
58+
- The given code is executed in the global scope, so imported objects from `react` package including `useState`, `useEffect`, ... are not accessible inside it and you should get them from `React` global variable :
5659

5760
```js
58-
import React from 'react';
61+
import {useState} from 'react';
5962
import StringToReactComponent from 'string-to-react-component';
60-
function MyComponent() {
61-
return <p>My Component</p>;
63+
function App() {
64+
return (
65+
<StringToReactComponent>
66+
{`()=>{
67+
console.log(typeof useState); // undefined
68+
console.log(typeof React.useState); // object
69+
70+
...
71+
72+
}`}
73+
</StringToReactComponent>
74+
);
6275
}
76+
```
77+
78+
## Using Unknown Elements
79+
80+
```js
81+
import StringToReactComponent from 'string-to-react-component';
82+
import MyComponent from 'path to MyComponent';
6383
function App() {
6484
return (
6585
<StringToReactComponent MyComponent={MyComponent}>

0 commit comments

Comments
 (0)