使用react-router更新fetch和useLoaderData()的方法
P粉883223328
P粉883223328 2023-08-26 12:39:34
0
1
337
<p>我想在提交表单后更新useLoaderData()的数据。 在我的情况下:</p> <pre class="brush:php;toolbar:false;">export const countriesLoader = async () =&gt; { const res = await fetch(&quot;https://restcountries.com/v3.1/all/&quot;); if (!res.ok) { throw Error(&quot;无法访问数据!&quot;); } return res.json(); };</pre> <p><code><路由索引元素={<CoutriesList />} loader={countriesLoader} /></code></p> <p>在CountriesList元素中:</p> <p><code>const国家= useLoaderData();</code></p> <p>我想要更新countries useLoaderData()中的新数据:</p> <pre class="brush:php;toolbar:false;">const findCountry = async () =&gt; { const res = await fetch( `https://restcountries.com/v3.1/name/${searchText}` ); const data = res.json(); return data; };</pre> <p>所以当我提交时,我希望countriesLoader的数据变成findCountry的数据。</p> <p>有什么解决方案吗?谢谢</p>
P粉883223328
P粉883223328

热门教程
더>
最新下载
더>
网站特效
网站源码
网站素材
프론트엔드 템플릿
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!