hook+ant design实现input多行编写小案例

前言

大家好 我是歌谣 最近在项目开发过程中 又学习到了一个小案例

代码

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;

效果

hook+ant design实现input多行编写小案例

原文链接:https://juejin.cn/post/7256754315258331192 作者:歌谣

(0)
上一篇 2023年7月18日 上午10:36
下一篇 2023年7月18日 上午10:46

相关推荐

发表回复

登录后才能评论