1. 程式人生 > >解決 嘗試更新已解除安裝(或無法掛載)的元件`Index`

解決 嘗試更新已解除安裝(或無法掛載)的元件`Index`

Attempted to update component Index that has already been unmounted (or failed to mount).

嘗試更新已解除安裝(或無法掛載)的元件Index

錯誤示例一:

錯誤程式碼:❌

@inject('CrumbStore')

constructor(props) {
  super(props);
  this.CrumbStore.addCrumb({   // this 改成 props ✅ 
    path: '/',
    breadcrumbName: '各大會場列表'
  });
}

錯誤示例二:

錯誤程式碼:❌

@inject('CrumbStore')

constructor(props) {
  super(props);
  const title = props.match.param.id && '會場編輯'; // param 改成 params ✅ 
}

錯誤示例三:

錯誤程式碼:❌

// 未引入CrumbStore  @inject('CrumbStore') ✅ 

constructor(props) {
  super(props);
  props.CrumbStore.setCurCrumb(
    { title: '測試' }
  );
}

警告 :Added synchronous DOM mutation listener to a event. Consider using MutationObserver to make the page more responsive.

為事件添加了同步DOM突變偵聽器。 考慮使用MutationObserver使頁面更具響應性。

錯誤程式碼:❌

@inject('CrumbStore')
// 新增 @observer 監聽元件 ✅ 
class Layout extends React.Component {
  // ... 
}