aboutsummaryrefslogtreecommitdiff
path: root/src/index.tsx
blob: 30d0f07374aef1afb1cb4e65e8148fbc99060166 (plain)
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
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import './style.css';
import './fonts/Bitter-Regular.woff';

import Timer from './components/Timer';

interface Solution {
  result: string;
  author: string;
}

const App: React.FC = () => {
  const [author, setAuthor] = useState<string>('anonymous');
  const [solutions, setSolutions] = useState<Solution[]>([]);

  const registerResult = (result: string) => {
    setSolutions([{ author, result }, ...solutions]);
  }

  return (
    <>
      <h2>Timer</h2>
      <Timer registerResult={registerResult} />

      <h2>Results</h2>
      <ul>
        {solutions.map(solution => (
          <li>
            {solution.result} by {solution.author}
          </li>
        ))}
      </ul>
    </>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));