我想在提交表单后更新useLoaderData()的数据。 在我的情况下:
export const countriesLoader = async () => {
const res = await fetch("https://restcountries.com/v3.1/all/");
if (!res.ok) {
throw Error("无法访问数据!");
}
return res.json();
};
<路由索引元素={
在CountriesList元素中:
const国家= useLoaderData();
我想要更新countries useLoaderData()中的新数据:
const findCountry = async () => {
const res = await fetch(
`https://restcountries.com/v3.1/name/${searchText}`
);
const data = res.json();
return data;
};
所以当我提交时,我希望countriesLoader的数据变成findCountry的数据。
有什么解决方案吗?谢谢
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号