我从代码中收到上述错误:<EditableContainer handleFn={this.onSaveTitle} component={FieldStyle}>{props.child}</EditableContainer>class EditableContainer extends React.Component<any, any> { render () { const {children, ...rest} = this.props const {edit} = this.state if (edit) { return ( <Component autoFocus onBlur={this.handleBlur.bind(this)} value={this.state.children} onChange={this.handleOnChange} render={(props) => this.props.component.render(props)} /> ) } }class FieldStyle extends React.Component<any, any> { render () { const {autoFocus, ...rest} = this.props // auto focus const ref = autoFocus ? (ref) => { this.ref = ref } : null return ( <TextField ref={ref} type="text" {...rest} /> ) }}正如你所看到的,我试图使用带有propEditableContainer的 React 来指定应该从哪个组件加载到实际组件本身。但是,我收到错误。Componentcomponent我究竟做错了什么?
1 回答
RISEBY
TA贡献1856条经验 获得超5个赞
我可能会把你的改成这个(注意中的props
大写):C
Component
<EditableContainer handleFn={this.onSaveTitle} Component={FieldStyle}>{props.child}</EditableContainer>
你需要像这样Component
解构:this.props
EditableContainer
const {children, Component, ...rest} = this.props
添加回答
举报
0/150
提交
取消