summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com>2021-05-30 10:21:35 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2021-06-01 22:36:56 +0200
commit76034880ae28dafce0d0192f55e1ef6815cf0c25 (patch)
tree1896dc0468847cdb1fbc316519a400e5858a70d9
parent768189859ab7737dc5a071a4126f90ad944f99dd (diff)
Add TypeScriptReact syntax test file
-rw-r--r--tests/syntax-tests/highlighted/TypeScriptReact/app.tsx35
-rw-r--r--tests/syntax-tests/source/TypeScriptReact/LICENSE.md25
-rw-r--r--tests/syntax-tests/source/TypeScriptReact/app.tsx35
3 files changed, 95 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/TypeScriptReact/app.tsx b/tests/syntax-tests/highlighted/TypeScriptReact/app.tsx
new file mode 100644
index 00000000..4fafc1ee
--- /dev/null
+++ b/tests/syntax-tests/highlighted/TypeScriptReact/app.tsx
@@ -0,0 +1,35 @@
+import * as React from "react";
+import { HelloComponent } from "./hello";
+import { NameEditComponent } from "./nameEdit";
+
+export const App = () => {
+ const [name, setName] = React.useState("defaultUserName");
+ const [editingName, setEditingName] = React.useState("defaultUserName");
+
+ const loadUsername = () => {
+ setTimeout(() => {
+ setName("name from async call");
+ setEditingName("name from async call");
+ }, 500);
+ };
+
+ React.useEffect(() => {
+ loadUsername();
+ }, []);
+
+ const setUsernameState = () => {
+ setName(editingName);
+ };
+
+ return (
+ <>
+ <HelloComponent userName={name} />
+ <NameEditComponent
+ initialUserName={name}
+ editingName={editingName}
+ onNameUpdated={setUsernameState}
+ onEditingNameUpdated={setEditingName}
+ />
+ </>
+ );
+};
diff --git a/tests/syntax-tests/source/TypeScriptReact/LICENSE.md b/tests/syntax-tests/source/TypeScriptReact/LICENSE.md
new file mode 100644
index 00000000..a2ac8db4
--- /dev/null
+++ b/tests/syntax-tests/source/TypeScriptReact/LICENSE.md
@@ -0,0 +1,25 @@
+The `app.tsx` file has been added from https://github.com/Lemoncode/react-typescript-samples under the following license:
+
+```text
+The MIT License (MIT)
+
+Copyright (c) 2016 brauliodiez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+```
diff --git a/tests/syntax-tests/source/TypeScriptReact/app.tsx b/tests/syntax-tests/source/TypeScriptReact/app.tsx
new file mode 100644
index 00000000..e02695fb
--- /dev/null
+++ b/tests/syntax-tests/source/TypeScriptReact/app.tsx
@@ -0,0 +1,35 @@
+import * as React from "react";
+import { HelloComponent } from "./hello";
+import { NameEditComponent } from "./nameEdit";
+
+export const App = () => {
+ const [name, setName] = React.useState("defaultUserName");
+ const [editingName, setEditingName] = React.useState("defaultUserName");
+
+ const loadUsername = () => {
+ setTimeout(() => {
+ setName("name from async call");
+ setEditingName("name from async call");
+ }, 500);
+ };
+
+ React.useEffect(() => {
+ loadUsername();
+ }, []);
+
+ const setUsernameState = () => {
+ setName(editingName);
+ };
+
+ return (
+ <>
+ <HelloComponent userName={name} />
+ <NameEditComponent
+ initialUserName={name}
+ editingName={editingName}
+ onNameUpdated={setUsernameState}
+ onEditingNameUpdated={setEditingName}
+ />
+ </>
+ );
+};