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

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

警告:無法對(duì)已卸載的組件執(zhí)行 React 狀態(tài)更新

警告:無法對(duì)已卸載的組件執(zhí)行 React 狀態(tài)更新

慕村9548890 2023-07-29 11:10:25
我收到以下警告:“警告:無法對(duì)已卸載的組件執(zhí)行 React 狀態(tài)更新。這是無操作,但它表明應(yīng)用程序中存在內(nèi)存泄漏。要修復(fù),請(qǐng)取消所有訂閱和異步任務(wù)在 useEffect 清理函數(shù)中。在 div 中的 AddComment(位于 CommentCard.js:50)中(由 Comment " 創(chuàng)建(CommentCard 中的第 50 行是 AddComment 組件所在的行)我有CommentCard組件,它在 ant design 的Comment組件的幫助下顯示評(píng)論。我使用 Comment 組件的 Children 屬性來顯示特定評(píng)論的AddComment組件。AddComment組件添加對(duì)評(píng)論的回復(fù)。為了顯示相應(yīng)評(píng)論的AddComment組件,我使用了狀態(tài)數(shù)組,并且僅針對(duì)狀態(tài)等于 1 的評(píng)論顯示該組件。添加回復(fù)后,我希望刪除AddComment組件。為此,我在成功添加回復(fù)后更改了評(píng)論的狀態(tài)。我發(fā)布回復(fù)后立即收到警告。這是我的 CommentCard 組件function CommentCard(props) {  const [hasReplyCommentBox, setHasReplyCommentBox] = useState([]);  const { t } = useTranslation();  const commentStyle = {    padding: '10px',    backgroundColor: 'white',    'whiteSpace': 'pre',    width: '100%'  };  function toggleReplyBoxVisibility(commentIndex) {    var auxState = { ...hasReplyCommentBox };    auxState[commentIndex] = auxState[commentIndex] ? 0 : 1;    setHasReplyCommentBox(auxState);  }  const actions = [    <span      id={"reply-button-" + props.commentIndex}      onClick={() => toggleReplyBoxVisibility(props.commentIndex)}>      {t('Reply to')}    </span>  ];  const commentReplyBox = (    hasReplyCommentBox[props.commentIndex]      ? <AddComment          id={props.codeId}          parentCommentId={props.parentCommentId}          commentIndex={props.commentIndex}          toggleReplyBoxVisibility={toggleReplyBoxVisibility}          updateComments={props.updateComments}        />      : null  );  return (    <Comment      author={props.userId}      datetime={props.datePosted}      content={props.body}      actions={actions}      children={commentReplyBox}      style={commentStyle}    />  );}
查看完整描述

1 回答

?
慕標(biāo)5832272

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

嘗試這個(gè)


function submitComment() {

    let request = {

      body: comment,

      code_id: props.id,

      line_number: props.lineNumber,

      parent_comment_id: props.parentCommentId

    };

    fetch('/api/comment/add',

      {

        method: 'POST',

        body: JSON.stringify(request)

      }

    ).then(response => response.json())

    .then(data => {

      if (data.success === 1) {

        props.updateComments();

        resetCommentInput();

        // Run resetCommentInput before props.toggleReplyBoxVisibility

        if (props.parentCommentId) {

          props.toggleReplyBoxVisibility(props.commentIndex);

        }

      }

    });

  }

您應(yīng)該在卸載之前更新組件狀態(tài)


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

添加回答

舉報(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)