Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit c090dc1

Browse files
committed
fix: remove prevent default and use react context
1 parent 6e2bfac commit c090dc1

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/components/DetailSidebar/DetailSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const DetailSidebar: React.FC = () => {
3838
/>
3939
<ActionBar />
4040
<Install />
41-
{packageMeta?.latest?.funding && <DetailSidebarFundButton to={packageMeta.latest.funding.url} />}
41+
<DetailSidebarFundButton />
4242
<Repository />
4343
<Engines />
4444
<Dist />

src/components/DetailSidebar/DetailSidebarFundButton.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React, { MouseEvent } from 'react';
1+
import React, { useContext } from 'react';
22
import styled from '@emotion/styled';
33
import Favorite from '@material-ui/icons/Favorite';
44

55
import Button from '../../muiComponents/Button';
66
import Link from '../Link';
77
import { Theme } from '../../design-tokens/theme';
8+
import { DetailContext } from '../../pages/Version';
89

910
const StyledLink = styled(Link)<{ theme?: Theme }>(({ theme }) => ({
1011
marginTop: theme && theme.spacing(1),
@@ -21,21 +22,21 @@ const StyledFundStrong = styled('strong')({
2122
marginRight: 3,
2223
});
2324

24-
interface Props {
25-
to: string;
26-
}
27-
2825
/* eslint-disable react/jsx-no-bind */
29-
const DetailSidebarFundButton: React.FC<Props> = ({ to }) => {
30-
const preventDefault = (event: MouseEvent<HTMLButtonElement>) => event.preventDefault();
26+
const DetailSidebarFundButton: React.FC = () => {
27+
const detailContext = useContext(DetailContext);
28+
29+
const { packageMeta } = detailContext;
30+
31+
if (!packageMeta?.latest?.funding) {
32+
return null;
33+
}
34+
35+
const to = packageMeta?.latest?.funding.url;
36+
3137
return (
3238
<StyledLink external={true} to={to}>
33-
<Button
34-
color="primary"
35-
fullWidth={true}
36-
onClick={preventDefault}
37-
startIcon={<StyledFavoriteIcon />}
38-
variant="outlined">
39+
<Button color="primary" fullWidth={true} startIcon={<StyledFavoriteIcon />} variant="outlined">
3940
<StyledFundStrong>{'Fund'}</StyledFundStrong>
4041
{'this package'}
4142
</Button>

0 commit comments

Comments
 (0)