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

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

錯(cuò)誤:函數(shù)組件不能有字符串引用。我們建議改用 useRef()

錯(cuò)誤:函數(shù)組件不能有字符串引用。我們建議改用 useRef()

慕田峪4524236 2022-12-22 14:44:54
我在我的 React 應(yīng)用程序中使用 ace Editor 并收到上述錯(cuò)誤。我想將我在我的 React 應(yīng)用程序中使用的 Ace Editor IDE 的內(nèi)容放在通過(guò)提交按鈕觸發(fā)的函數(shù)調(diào)用中。<AceEditorref='aceEditor'height='100%'width='100%'mode={ideLanguage}theme={ideTheme}fontSize={ideFontSize}showGutter={true}showPrintMargin={false}/>這是按鈕<Buttontype='button'buttonStyle='btn--primary--normal'buttonSize='btn--medium'onClick={SendCode}>SUBMIT</Button>這是功能const SendCode = () => {  console.log(this.refs.aceEditor.editor.getValue());};我究竟做錯(cuò)了什么??
查看完整描述

1 回答

?
肥皂起泡泡

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

字符串引用是設(shè)置 DOM 引用的傳統(tǒng)方式。

在最新的 React 版本中,建議對(duì)功能組件和類組件使用React.useRef()鉤子。React.createRef()

您可以閱讀更多詳細(xì)信息 - https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs

我猜,你可能已經(jīng)打開(kāi)了<React.StrictMode>高階組件的嚴(yán)格模式。這就是為什么會(huì)拋出錯(cuò)誤/警告的原因。

你應(yīng)該做什么 -

  1. 聲明一個(gè) ref 變量。

    const aceEditorRef = useRef();

  2. 之后,替換ref='aceEditor'ref={aceEditorRef}

 <AceEditor

    ref={aceEditorRef}

    height='100%'

    width='100%'

    mode={ideLanguage}

    theme={ideTheme}

    fontSize={ideFontSize}

    showGutter={true}

    showPrintMargin={false}/>

使用 aceEditorRef.current 獲取 DOM 引用


const SendCode = () => {

  console.log(this.aceEditorRef.current.editor.getValue());

};


查看完整回答
反對(duì) 回復(fù) 2022-12-22
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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