假设我的
应用程序
组件看起来像:
import { Form } from "react-final-form";
myInitData = {
firstName: "akira",
lastName: "fubuki"
}
render() {
return
<Form
initialValues={myInitData}
onSubmit={this.handleSubmit}
validate={this.validate}
>
{({handleSubmit, submitting, values}) => (
<MyComponentOuter
someProp1={100}
someProp2={200}
/>
)}
</Form>
}
此外,我还有一些组件
支原体
在内部
MycomponentOuter公司
所以层次结构是app=>mycomponentouter=>mycomponentinner
支原体
看起来像:
class MyComponentInner extends Component {
componentDidMount() {
console.log(????) //how do i get access to firstName here..?
}
render() {
return (
<label>first name</label>
<Field
name="firstName"
component="input"
type="text"
/>
)
}
}
我的问题是:
a)react final form的组件如何自动访问“firstname”属性?(没有明确传递道具)。
b)我想在mycomponentinner中访问相同的firstname值;语法是什么,例如,如果我想console.log firstname。