例如:
import { useState, useEffect } from 'react';
import { Input } from 'antd';
import axios from 'axios';
const ExampleComponent = () => {
const [list, setList] = useState([]);
const [inputValue, setInputValue] = useState('');
useEffect(() => {
const getList = async () => {
const result = await axios.get('/api/list');
setList(result.data);
}
getList();
}, []);
const handleInputChange = (event: React.ChangeEvent) => {
setInputValue(event.target.value);
}
return (
{list.map(item => - {item.name}
)}
)
}
例如:
import { useState, useEffect } from 'react';
import { Input } from 'antd';
import axios from 'axios';
const ExampleComponent = () => {
const [list, setList] = useState([]);
const [inputValue, setInputValue] = useState('');
useEffect(() => {
const fetchData = async () => {
try {
const result = await axios.get('/api/list');
setList(result.data);
} catch (error) {
console.log(error);
}
}
fetchData();
}, []);
const handleInputChange = (event: React.ChangeEvent) => {
setInputValue(event.target.value);
}
return (
{list.map(item => - {item.name}
)}
)
}