【发布时间】:2018-09-12 07:42:56
【问题描述】:
我不确定我是否根据我的问题来表达我的问题,但也许代码会有所帮助:
import React from 'react';
import PropTypes from 'prop-types';
import { Component } from 'kawax-js';
class Reference extends React.Component {
state={fileDisplayed:""}
static propTypes = {
getFile: PropTypes.func.isRequired,
content: PropTypes.object
}
static defaultProps = {
content: Object()
}
componentDidMount = async() => {
this.props.getFile(this.props.match.params.refHash);
}
componentWillUnmount() {
}
....
当我尝试在组件之间切换时出现内存泄漏错误。一旦我想返回上一个组件,如何确保来自 componentDidMount 的函数调用在 componentWillUnmount 中被取消?
【问题讨论】:
-
1.函数调用在内部做什么?特别是,该函数的代码的哪一部分取决于您组件的生命周期? 2. componentDidMount 是异步的,但它没有返回
getFile承诺。这将为getFile生成一个单独的承诺上下文。
标签: javascript reactjs components lifecycle