forked from isaacplmann/sturdy-uis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
53 lines (49 loc) · 1.38 KB
/
Copy pathApp.tsx
File metadata and controls
53 lines (49 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { useEffect } from 'react';
import { fetchPeople, fetchPlanets } from './api';
import './App.css';
import List from './list/List';
import { matchingMachine } from './machines/matching';
import { useMachine } from '@xstate/react';
export interface Person {
name: string;
homeworld: string;
}
function App() {
const [machine, send] = useMachine(matchingMachine, {
guards: {
isCorrect: (ctx, event) =>
ctx.leftSelectedItem.homeworld === ctx.rightSelectedItem.url
}
});
return (
<div className="App">
{machine.matches('answering') ? (
<>
<List
fetchData={fetchPeople}
onSelection={selectedItem => {
send({ type: 'selectLeft', selectedItem });
}}
></List>
<hr></hr>
<List
fetchData={fetchPlanets}
onSelection={selectedItem => {
send({ type: 'selectRight', selectedItem });
}}
></List>
</>
) : null}
{machine.matches('submitted') ? (
<button onClick={() => send({ type: 'reset' })}>Reset</button>
) : null}
{machine.matches('submitted.correct') ? (
<p>The force is strong with this one.</p>
) : null}
{machine.matches('submitted.incorrect') ? (
<p>Do, or do not. There is no try.</p>
) : null}
</div>
);
}
export default App;