[英]I'm trying to make a CRUD and I'm not able to send the <Select> data with 'react-select' dependencie
[英]I'm trying to make a select component in React but onChange listener is not working
我想在我的表單中創建一個 select 國家/地區組件,但在我的<select>
onChange 偵聽器中由於某種原因無法正常工作
<Form.Group className="form-group">
<Form.Label htmlFor="country">Country</Form.Label>
<div className="form-control-wrap">
<select className="form-select form-select-lg" id="country" name="country"
onChange={e => console.log("Changed")}>
<option value={"select-country"}>Select Country</option>
{
countries.map((c) => {
return (<option value={c.name}>{c.name}</option>)})}
</select>
</div>
</Form.Group>
當我 select 一個國家/地區什么都不會打印在控制台上時,應該在那里打印“已更改”
我不確定問題是什么,它有效。 你能創建一個這樣的代碼片段來重現你的錯誤嗎?
const countries = [{ name: 'germany' }]; const App = () => { return ( <select className="form-select form-select-lg" id="country" name="country" onChange={e => console.log("Changed")}> <option value="select-country">Select Country</option> {countries.map((c) => <option value={c.name}>{c.name}</option>)} </select> ) }; ReactDOM.render(<App />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script> <div id="app">hi</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.