第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

寫(xiě)了一個(gè)React的HOC出了點(diǎn)問(wèn)題

寫(xiě)了一個(gè)React的HOC出了點(diǎn)問(wèn)題

森林海 2019-03-13 17:19:35
HOC功能:接受antd組件中的Input | TextArea等輸入組件,將 lodash 中的 debounce 方法注入到 onchange 事件當(dāng)中。代碼如下:import React, {Component} from 'react';import {debounce} from 'lodash';export default (WrapperComponent) => {    // WrapperComponent 就是傳入的  `Input` | `TextArea` 組件    return class extends Component {        constructor() {            super(...arguments);            this.state = {                value: null            }        }        // input onChange 方法        changeHandler = (e) => {            e.persist();            this.delayChange(e.target.value.trim());        }        //         componentWillMount() {            this.delayChange = debounce((v) => {                this.setState({value: v});            }, 300);        }        render () {            const {value} = this.state;            if(!value) return null;            return <WrapperComponent                defaultValue={value ? value : null}                onChange={this.changeHandler}                onBlur={this.saveInputValue}            />;        }    };};在調(diào)用的時(shí)候報(bào)warning了,如下:Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.還有一個(gè)問(wèn)題是:怎么能把 WrapperComponent 組件上的數(shù)據(jù),拿到當(dāng)前的高階組件內(nèi)部?補(bǔ)充:高階組件調(diào)用:import {Input} from 'antd';HOC(<Input />)
查看完整描述

1 回答

?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

傳進(jìn)去的<Input />React Element而非class,因此調(diào)用處直接寫(xiě)HOC(Input)即可

第二個(gè)問(wèn)題,你在HOC中獲取的是class而不是React Element,而組件數(shù)據(jù)是相對(duì)React Element而言的,因此答案是無(wú)法獲取


查看完整回答
反對(duì) 回復(fù) 2019-03-27
  • 1 回答
  • 0 關(guān)注
  • 540 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)