react-app-shell
Version:
react打包脚本和example, 这里的版本请忽略
37 lines (30 loc) • 684 B
JavaScript
import {PureComponent} from 'react';
import PropTypes from 'prop-types';
/**
* 文档标题
*/
export default class DocumentTitle extends PureComponent {
static propTypes = {
title: PropTypes.string
};
static defaultProps = {
title: ''
};
componentDidMount() {
this.setTitle(this.props.title);
}
componentWillReceiveProps(nextProps) {
if (nextProps.title && nextProps.title !== this.props.title) {
this.setTitle(nextProps.title);
}
}
/**
* 设置文档标题
*/
setTitle = title => {
window.document.title = title;
};
render() {
return null;
}
}