Reactjs React/Redux-如何将值从Redux存储传递到onClick处理程序内部的函数中
我有一个组件,其中有一个函数,可以通过redux中的Reactjs React/Redux-如何将值从Redux存储传递到onClick处理程序内部的函数中,reactjs,react-redux,Reactjs,React Redux,我有一个组件,其中有一个函数,可以通过redux中的字段array呈现位置列表,我正试图找出当从父组件设置初始值时,如何访问名为\u id的属性 下面是呈现列表的函数: renderLocations({ fields, meta: { touched, error, submitFailed } }) { return ( <div> <div className={styles.contactInfoSection}>
字段array
呈现位置列表,我正试图找出当从父组件设置初始值时,如何访问名为\u id
的属性
下面是呈现列表的函数:
renderLocations({ fields, meta: { touched, error, submitFailed } }) {
return (
<div>
<div className={styles.contactInfoSection}>
<h2>Locations</h2>
<div>
<button type="button" className={styles.add} onClick={() => fields.push({})}>Add Location</button>
{(touched || submitFailed) && error && <span>{error}</span>}
</div>
</div>
<ul className={styles.locationsList}>
{fields.map((location, index) =>
<li className={styles.locationCard} key={index}>
<div>
<Field
name={`${location}.street`}
hintText="Street"
component={TextField}
label="Street"/>
<Field
name={`${location}.city`}
hintText="City"
component={TextField}
label="City"/>
<Field
name={`${location}.state`}
hintText="State"
component={TextField}
label="State"/>
<Field
name={`${location}.zip`}
hintText="Zip"
component={TextField}
label="Zip"/>
</div>
<button
type="button"
title="Remove"
onClick={() => {
fields.remove(index);
this.removeLocation(<locationId?>); // I need to be able to pass in an _id from the initialValues here
}}>Remove</button>
</li>
)}
</ul>
</div>
);
}
renderLocations({fields,meta:{toucted,error,submitFailed}}){
返回(
位置
fields.push({})}>添加位置
{(触摸| |提交失败)&&error&&error}
{fields.map((位置、索引)=>
-
{
字段。删除(索引);
this.removeLocation();//我需要能够从这里的初始值传入一个_id
}}>除去
)}
);
}
然后作为参考:
<ManageCustomerForm
initialValues={this.state.customer} />
this.state.customer
有一个locations
属性,该属性映射到包含位置的\u id
的对象数组,以及一些其他数据。如果父组件正在传递状态,那么子组件不必通过道具访问该状态吗?
?您可以在位置数组中显示对象的结构吗?