亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 239 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號