Cómo asignar un valor predeterminado en Seleccionar mientras lo renderiza. Por ejemplo, qué valor predeterminado se seleccionó jack . Intenté insertar en el conector de valor defaulValue ( Seleccionar accesorios ), pero Seleccionar no devuelve un valor, pero visualmente se seleccionó. codigosandbox
Simplemente agregue el archivo demo.js. Agregué solo valor predeterminado y valor en opciones. https://codesandbox.io/embed/custom-dropdown-antd-4-21-5-forked-ip8nn8?fontsize=14&hidenavigation=1&theme=dark
import React, { useState } from "react"; import "antd/dist/antd.css"; import "./index.css"; import { PlusOutlined } from "@ant-design/icons"; import { Divider, Input, Select, Space, Typography } from "antd"; const { Option } = Select; let index = 0; const App = () => { const [items, setItems] = useState(["jack", "lucy"]); const [name, setName] = useState(""); const onNameChange = (event) => { setName(event.target.value); }; const addItem = (e) => { e.preventDefault(); setItems([...items, name || `New item ${index++}`]); setName(""); }; return ( <> <Select style={{ width: 300 }} defaultValue={items[0]} placeholder="custom dropdown render" dropdownRender={(menu) => ( <> {menu} <Divider style={{ margin: "8px 0" }} /> <Space align="center" style={{ padding: "0 8px 4px" }} > <Input placeholder="Please enter item" value={name} onChange={onNameChange} /> <Typography.Link onClick={addItem} style={{ whiteSpace: "nowrap" }} > <PlusOutlined /> Add item </Typography.Link> </Space> </> )} > {items.map((item) => ( <Option value={item} key={item}> {item} </Option> ))} </Select> </> ); }; export default App;