You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-42Lines changed: 48 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,7 @@ function App() {
50
50
return (
51
51
<StringToReactComponent>
52
52
{`(props)=>{
53
-
const {useState}=React;
54
-
const [counter,setCounter]=useState(0);
53
+
const [counter,setCounter]=React.useState(0); // by default your code has access to the React object
55
54
const increase=()=>{
56
55
setCounter(counter+1);
57
56
};
@@ -69,25 +68,25 @@ function App() {
69
68
70
69
- The given code inside the string should be a function.
71
70
72
-
- The code inside the string is executed in the global scope, so imported objects from `react` package including `useState`, `useEffect`, ... are not accessible inside it and you can get them from `React`global variable or pass them as props to the component:
- The code inside the string has access to the `React` object and for using `useState`, `useEffect`, `useRef` and ... you should get them from `React`object or pass them as `data` prop to the component:
Copy file name to clipboardExpand all lines: example/stories/using-react-hooks/README.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
Your imported object including `useState`, `useEffect`, `useRef` and ... are not accessible inside the string code but you can get them from `React` object ( by default `React` object is emmbed into your string code ) or pass them as the `data` prop
1
+
The code inside the string has access to the `React`object and for using `useState`, `useEffect`, `useRef` and ... you should get them from `React` object or pass them as `data` prop to the component
2
2
3
3
```jsx
4
4
import {useState} from'react';
@@ -10,8 +10,8 @@ function App() {
10
10
{`(props)=>{
11
11
return (<>
12
12
<p>type of imported useState is {typeof useState}</p>
13
+
<p>type of React is {typeof React}</p>
13
14
<p>type of React.useState is {typeof React.useState}</p>
14
-
<p>type of React is {typeof React} ( by default React object is emmbed into your string code )</p>
15
15
<p>type of props.useState is {typeof props.useState}</p>
0 commit comments