我有以下元素:

作為反應,我剛剛宣告了以下內容:
const [type, setType] = useState("");
const [propertyName, setPropertyName] = useState("");
html如下:
<div>
<label htmlFor='properties' className='properties-label'>
Properties
</label>
<div className='property-box'>
<input
type='text'
id='type'
placeholder='Type'
className='type-element'
required
onChange={(e) => setType(e.target.value)}
></input>
<input
type='text'
id='name'
className='type-element'
placeholder='Name'
required
onChange={(e) => setPropertyName(e.target.value)}
></input>
<button className='buttonAccount' type='submit'>
Add Property
</button>
</div>
</div>
我想要的基本上是以某種方式添加一個包含兩個值的屬性。我正在考慮使用陣列來存盤一些物件,例如以下示例: { type: card name: Dragon }
但我真的不知道如何解決這個問題。我應該先創建一個空陣列,然后將這兩個欄位存盤在一個物件中嗎?這是怎么做到的?如何確保兩個欄位都已完成(如果其中一個為空,則不應進入資料庫)。輸入這兩個欄位后,我希望在這些欄位下方出現一個新元素,就像我介紹的資料的段落一樣,我看到的一個熟悉的示例是在 OpenSea 上,在創建 NFT 時(https://opensea .io/asset/create)有人可以解釋一下解決這個問題的方法嗎?
uj5u.com熱心網友回復:
你可以看看這段代碼
https://codesandbox.io/s/crazy-lake-059b82?file=/src/App.js:0-1339
要使段落可見,請再創建一個狀態并在 handleClick 函式上對其進行更新
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/433000.html
標籤:javascript html 反应
上一篇:使用cheerio報廢網頁時如何解決“錯誤:無法驗證第一個證書”?
下一篇:使用反應鉤子的多步表單
