Projekt

Obecné

Profil

Stáhnout (885 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
// Example component that connects to the backend API and fetches dummy data
2

    
3
import { useState } from 'react'
4
import AxiosClient from '../services/AxiosClient'
5

    
6
const StubComponent = () => {
7

    
8
    const [text, setText] = useState<string>('')
9

    
10
    // Sends api request to the backend
11
    const fetchStub = async () => {
12
        try {
13
            const { data } = await AxiosClient.get('/stub')
14
            if (!!data && data.success) {
15
                setText(data.message as string)
16
            }
17
        }
18
        catch (err) {
19
            console.log(`An error has occurred: ${err}`)
20
        }
21
    }
22

    
23
    return (
24
        <>
25
            <h1>Welcome to the internet</h1>
26
            <p>Click the button to fetch the message</p>
27
            <p>The message: {text}</p>
28
            <button onClick={fetchStub}>Fetch the message</button>
29
        </>
30
    )
31

    
32
}
33

    
34
export default StubComponent
    (1-1/1)