hook+ant design实现文本Input多行编辑

代码

a35dd72527ec4c4646dee9a90a66aea6.png

import { Input } from 'antd';
import React, { useState } from 'react';




const DynamicPage = () => {
    const [inputList, setInputList] = useState<string[]>(['']);
    const handleInputChange = (e: any) => {
        console.log('e', e.target.value, e.target.id);
        let temp = JSON.parse(JSON.stringify(inputList));


        temp[Number(e.target.id)] = e.target.value;
        if(temp[temp.length - 1] !== ''){
            temp.push('');
        }


        setInputList(temp);
    }




    return(
        <div>
            {
                inputList && inputList.map((it, idx) => {
                    return(
                        <Input id = {idx.toString()} value = {it} onChange={handleInputChange}></Input>
                    )
                })
            }
        </div>
    )
        }


export default DynamicPage;

效果

b82aa94dbf3cc80006aa12976f3b529f.png

3c9bb0742377dab3f7d948c202867f41.png

posted @ 2023-05-29 20:52  前端导师歌谣  阅读(36)  评论(0)    收藏  举报  来源