There is no need for a class component here

We should use function component as much as possible, because their are easier to read and less confusing.
This commit is contained in:
Sebastian Sdorra
2020-10-15 08:34:36 +02:00
parent e67ca28c5f
commit ffd1daba52

View File

@@ -22,21 +22,19 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React, { FC } from "react";
import { WithTranslation, withTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import Notification from "../Notification"; import Notification from "../Notification";
import { Me } from "@scm-manager/ui-types"; import { Me } from "@scm-manager/ui-types";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { compose } from "redux";
type Props = WithTranslation & { type Props = {
// props from global state // props from global state
me: Me; me: Me;
}; };
class CommitAuthor extends React.Component<Props> { const CommitAuthor: FC<Props> = ({ me }) => {
render() { const [t] = useTranslation("repos");
const { me, t } = this.props;
const mail = me.mail ? me.mail : me.fallbackMail; const mail = me.mail ? me.mail : me.fallbackMail;
@@ -48,8 +46,7 @@ class CommitAuthor extends React.Component<Props> {
</span> </span>
</> </>
); );
} };
}
const mapStateToProps = (state: any) => { const mapStateToProps = (state: any) => {
const { auth } = state; const { auth } = state;
@@ -60,4 +57,4 @@ const mapStateToProps = (state: any) => {
}; };
}; };
export default compose(connect(mapStateToProps), withTranslation("repos"))(CommitAuthor); export default connect(mapStateToProps)(CommitAuthor);