on master help sign in
Add TypeScriptReact syntax test file
commit76034880ae28dafce0d0192f55e1ef6815cf0c25 authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com> dateSun 30 May 2021, 10:21 (5 years ago) parent7681898
3 files changed+95
tests/syntax-tests/highlighted/TypeScriptReact/app.tsx+35 tests/syntax-tests/source/TypeScriptReact/LICENSE.md+25 tests/syntax-tests/source/TypeScriptReact/app.tsx+35
tests/syntax-tests/highlighted/TypeScriptReact/app.tsxnew file+35
@@ -0,0 +1,35 @@
1+import * as React from "react";
2+import { HelloComponent } from "./hello";
3+import { NameEditComponent } from "./nameEdit";
4+
5+export const App = () => {
6+ const [name, setName] = React.useState("defaultUserName");
7+ const [editingName, setEditingName] = React.useState("defaultUserName");
8+
9+ const loadUsername = () => {
10+ setTimeout(() => {
11+ setName("name from async call");
12+ setEditingName("name from async call");
13+ }, 500);
14+ };
15+
16+ React.useEffect(() => {
17+ loadUsername();
18+ }, []);
19+
20+ const setUsernameState = () => {
21+ setName(editingName);
22+ };
23+
24+ return (
25+ <>
26+ <HelloComponent userName={name} />
27+ <NameEditComponent
28+ initialUserName={name}
29+ editingName={editingName}
30+ onNameUpdated={setUsernameState}
31+ onEditingNameUpdated={setEditingName}
32+ />
33+ </>
34+ );
35+};
tests/syntax-tests/source/TypeScriptReact/LICENSE.mdnew file+25
@@ -0,0 +1,25 @@
1+The `app.tsx` file has been added from https://github.com/Lemoncode/react-typescript-samples under the following license:
2+
3+```text
4+The MIT License (MIT)
5+
6+Copyright (c) 2016 brauliodiez
7+
8+Permission is hereby granted, free of charge, to any person obtaining a copy
9+of this software and associated documentation files (the "Software"), to deal
10+in the Software without restriction, including without limitation the rights
11+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+copies of the Software, and to permit persons to whom the Software is
13+furnished to do so, subject to the following conditions:
14+
15+The above copyright notice and this permission notice shall be included in all
16+copies or substantial portions of the Software.
17+
18+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+SOFTWARE.
25+```
tests/syntax-tests/source/TypeScriptReact/app.tsxnew file+35
@@ -0,0 +1,35 @@
1+import * as React from "react";
2+import { HelloComponent } from "./hello";
3+import { NameEditComponent } from "./nameEdit";
4+
5+export const App = () => {
6+ const [name, setName] = React.useState("defaultUserName");
7+ const [editingName, setEditingName] = React.useState("defaultUserName");
8+
9+ const loadUsername = () => {
10+ setTimeout(() => {
11+ setName("name from async call");
12+ setEditingName("name from async call");
13+ }, 500);
14+ };
15+
16+ React.useEffect(() => {
17+ loadUsername();
18+ }, []);
19+
20+ const setUsernameState = () => {
21+ setName(editingName);
22+ };
23+
24+ return (
25+ <>
26+ <HelloComponent userName={name} />
27+ <NameEditComponent
28+ initialUserName={name}
29+ editingName={editingName}
30+ onNameUpdated={setUsernameState}
31+ onEditingNameUpdated={setEditingName}
32+ />
33+ </>
34+ );
35+};