Skip to content

Commit

Permalink
_target="blank" for external URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Apr 15, 2024
1 parent f014de6 commit b821f7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Here is a simple table that reproduces the error on this page (when `window.inne


[react-data-table-component]: https://github.com/jbetancur/react-data-table-component
[localhost:3000]: http://localhost:3000
[localhost:3000]: http://localhost:3000/

[react#418]: https://react.dev/errors/418?invariant=418

Expand Down
28 changes: 18 additions & 10 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import DataTable from "react-data-table-component";
import ReactMarkdown from "react-markdown";
import ReactMarkdown, { Components } from "react-markdown";
import fs from "fs";
import Link from "next/link";

export function getStaticProps() {
return { props: { readme: fs.readFileSync("README.md").toString() } }
}

const components: Components = {
a: ({ href, children }) =>
<Link href={href || "#"} target={href?.startsWith("http") ? "_blank" : "_self"}>
{children}
</Link>
}

const Index = ({ readme }: { readme: string }) =>
<div className={"markdown-body"}>
<ReactMarkdown>{readme}</ReactMarkdown>
<DataTable
columns={[ { name: "Str" }, { name: "Num" } ]}
data={[ { Str: "A", Num: 1 } ]}
// This line causes a hydration error in the pagination footer "nav" element (iff the
// browser window is ≥599px wide); commenting this line fixes it.
pagination
/>
</div>
<ReactMarkdown components={components}>{readme}</ReactMarkdown>
<DataTable
columns={[ { name: "Str" }, { name: "Num" } ]}
data={[ { Str: "A", Num: 1 } ]}
// This line causes a hydration error in the pagination footer "nav" element (iff the
// browser window is ≥599px wide); commenting this line fixes it.
pagination
/>
</div>

export default Index

0 comments on commit b821f7c

Please sign in to comment.