阅读 1

test

import react from 'react'
复制代码
import React, { useState, useEffect } from 'react';

const SOME_API = '/api/get/value';

export const MyComponent: React.FC<{}> = () => {
    const [loading, setLoading] = useState(true);
    const [value, setValue] = useState(0);

    useEffect(() => {
        (async () => {
            const res = await fetch(SOME_API);
            const data = await res.json();
            setValue(data.value);
            setLoading(false);
        })();
    }, []);

    return (
        <>
        {loading ? (
            <h2>Loading...</h2>
        ) : (
            <h2>value is {value}</h2>
        )}
        </>
    );
}
复制代码
import React, { useState, useEffect } from 'react';
const SOME_API = '/api/get/value';
export const MyComponents:React.FC<{}> = () => {
    return (
        <>
            <span>Value is {value}</span>
            <button onClick={dealClick}>Click Me!</button>
        </>
    );
}
复制代码
关注下面的标签,发现更多相似文章
评论