如何解决如何使用“名称”查找客户组件的对应值
嗨,我定义了我的客户反应组件,例如:
export interface ArrayProps {
value: string[],labeltext: string,setValue: Dispatch<SetStateAction<string[]>>
}
export const ArrayInput =(props: ArrayProps)=>{
var [fields,setFields]=useState<string[]>(props.value);
const addfields=()=>{
const tmp = [...fields]
tmp.push("")
setFields(tmp)
props.setValue(tmp)
}
const removefields=()=>{
const tmp = [...fields]
tmp.pop()
setFields(tmp)
props.setValue(tmp)
}
useEffect(()=>{
rendinglist()
},[fields])
const chnageInput=(index:number,value:string)=>{
const tmp= [...fields]
tmp[index]=value;
setFields(tmp)
props.setValue(tmp)
}
// const txtInput=(e: ChangeEvent<>)=>{
// }
const rendinglist=()=>{
return fields.map(key=>(<li><TextField value={key} label="mail extension"></TextField></li>))
}
return (
<ul>
<p><button type="button" onClick={addfields}>
Add
</button>
<button type="button" onClick={removefields}>
remove
</button></p>
{fields.map((key,index)=>(<li><TextField label={props.labeltext} color="secondary" value={key} key={`k${index}`} onChange={(val: ChangeEvent<HTMLInputElement>)=>{
chnageInput(index,val.target.value)
}}/></li>))}
</ul>)
}
但是然后我使用formik,formik使用名称来获取值,例如:
initialvalue= {"mycomponent": "my test"}
然后我定义Component:
<input type="text" name="mycomponent"></input>
则输入值应为“我的测试”,
我的客户部分应如何做类似的员工?
如何使用“名称”设置客户组件的值?
我想使用通过名称属性获取客户组件的值。怎么做?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。