Przeglądaj źródła

attach next link

jam411 3 lat temu
rodzic
commit
33d848cc2c
1 zmienionych plików z 16 dodań i 18 usunięć
  1. 16 18
      packages/app/src/components/User/Username.jsx

+ 16 - 18
packages/app/src/components/User/Username.jsx

@@ -1,30 +1,28 @@
 import React from 'react';
+
+import Link from 'next/link';
 import PropTypes from 'prop-types';
 
-export default class Username extends React.Component {
+const Username = (props) => {
+  const { user } = props;
 
-  renderForNull() {
+  if (user == null) {
     return <span>anyone</span>;
   }
 
-  render() {
-    const { user } = this.props;
-
-    if (user == null) {
-      return this.renderForNull();
-    }
+  const name = user.name || '(no name)';
+  const username = user.username;
+  const href = `/user/${user.username}`;
 
-    const name = user.name || '(no name)';
-    const username = user.username;
-    const href = `/user/${user.username}`;
-
-    return (
-      <a href={href}>{name} (@{username})</a>
-    );
-  }
-
-}
+  return (
+    <Link href={href}>
+      <a>{name} (@{username})</a>
+    </Link>
+  );
+};
 
 Username.propTypes = {
   user: PropTypes.oneOfType([PropTypes.object, PropTypes.string]), // Possibility of receiving a string of 'null'
 };
+
+export default Username;