使用react-router更新fetch和useLoaderData()的方法
P粉883223328
P粉883223328 2023-08-26 12:39:34
0
1
336
<p>我想在提交表單後更新useLoaderData()的資料。 在我的情況下:</p> <pre class="brush:php;toolbar:false;">export const countriesLoader = async () => { const res = await fetch("https://restcountries.com/v3.1/all/"); if (!res.ok) { throw Error("無法存取資料!"); } 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 () => { 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學習者快速成長!