mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
35 lines
780 B
TypeScript
35 lines
780 B
TypeScript
import * as React from "react";
|
|
import * as withSideEffect from "react-side-effect";
|
|
|
|
interface DocumentTitleProps {
|
|
title: string
|
|
}
|
|
|
|
class DocumentTitle extends React.Component<DocumentTitleProps, any> {
|
|
public render() {
|
|
if (this.props.children) {
|
|
return React.Children.only(this.props.children);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
function reducePropsToState(propsList: any[]) {
|
|
var innermostProps = propsList[propsList.length - 1];
|
|
if (innermostProps) {
|
|
return innermostProps.title;
|
|
}
|
|
}
|
|
|
|
function handleStateChangeOnClient(title: string) {
|
|
document.title = title || "";
|
|
}
|
|
|
|
let DocumentTitleWithSideEffects = withSideEffect(
|
|
reducePropsToState,
|
|
handleStateChangeOnClient
|
|
)(DocumentTitle);
|
|
|
|
export default DocumentTitleWithSideEffects;
|