为了账号安全,请及时绑定邮箱和手机立即绑定

React:在返回的组件实例上找不到“render”方法:您可能忘记定义“render”

React:在返回的组件实例上找不到“render”方法:您可能忘记定义“render”

互换的青春 2023-07-14 10:19:49
我从代码中收到上述错误:<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大写):CComponent

<EditableContainer handleFn={this.onSaveTitle} Component={FieldStyle}>{props.child}</EditableContainer>

你需要像这样Component解构:this.propsEditableContainer

const {children, Component, ...rest} = this.props


查看完整回答
反对 回复 2023-07-14
  • 1 回答
  • 0 关注
  • 123 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信