-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix react 16.13 compatibility: Cannot update a component from inside …
…the function body of a different component.
- Loading branch information
Showing
5 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Hello World</title> | ||
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script> | ||
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script> | ||
|
||
<!-- Don't use this in production: --> | ||
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script src="./lib/umd/reto.js"></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="text/babel"> | ||
const {Provider, useStore} = reto | ||
const {useState} = React | ||
|
||
function FooStore(initial = 1) { | ||
const [x, setX] = useState(initial) | ||
return { | ||
x, | ||
setX | ||
} | ||
} | ||
|
||
const App = (props) => { | ||
const fooStore = useStore(FooStore) | ||
|
||
function changeStore() { | ||
fooStore.setX(fooStore.x + 1) | ||
} | ||
return ( | ||
<div> | ||
<button onClick={changeStore}>Change</button> | ||
{fooStore.x} | ||
</div> | ||
) | ||
} | ||
|
||
ReactDOM.render( | ||
<h1> | ||
Hello, world! | ||
<Provider of={FooStore}> | ||
<App/> | ||
</Provider> | ||
</h1>, | ||
document.getElementById('root') | ||
); | ||
|
||
</script> | ||
<!-- | ||
Note: this page is a great way to try React but it's not suitable for production. | ||
It slowly compiles JSX with Babel in the browser and uses a large development build of React. | ||
Read this section for a production-ready setup with JSX: | ||
https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project | ||
In a larger project, you can use an integrated toolchain that includes JSX instead: | ||
https://reactjs.org/docs/create-a-new-react-app.html | ||
You can also use React without JSX, in which case you can remove Babel: | ||
https://reactjs.org/docs/react-without-jsx.html | ||
--> | ||
</body> | ||
</html> |