2 回答

TA貢獻1824條經(jīng)驗 獲得超8個贊

TA貢獻1783條經(jīng)驗 獲得超4個贊
使用 useState 掛鉤。它將在更改時重新呈現(xiàn)組件。
const initialValue = [
{
id: 9,
email: "michael.lawson@reqres.in",
first_name: "Michael",
last_name: "Lawson",
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/follettkyle/128.jpg"
},
{
id: 10,
email: "lindsay.ferguson@reqres.in",
first_name: "Lindsay",
last_name: "Ferguson",
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/araa3185/128.jpg"
}
];
export default function App() {
const [people, setPeople] = useState(initialValue);
const handleClick = () => {
return axios.get(`https://reqres.in/api/users?page=2`).then(res => {
setPeople(res.data.data);
});
};
return (
<div className="App">
<Button color="primary" type="Submit" onClick={handleClick}>
click me !!!
</Button>
<EleventHeaderCard />
</div>
);
}
添加回答
舉報