8000 docs: prevent redirects from live preview (#6858) · react-bootstrap/react-bootstrap@dc802d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc802d9

Browse files
docs: prevent redirects from live preview (#6858)
1 parent 965efee commit dc802d9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

www/src/theme/Playground/Preview.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LiveContext, LivePreview } from 'react-live';
44
import qsa from 'dom-helpers/querySelectorAll';
55
import useIsomorphicEffect from '@restart/hooks/useIsomorphicEffect';
66
import useMutationObserver from '@restart/hooks/useMutationObserver';
7+
import useEventCallback from '@restart/hooks/useEventCallback';
78

89
export interface PreviewProps {
910
className?: string | undefined;
@@ -55,9 +56,15 @@ const Preview: React.FC<PreviewProps> = ({ className }) => {
5556
},
5657
);
5758

59+
const handleCustomRedirect = useEventCallback((e: React.MouseEvent<HTMLElement>) => {
60+
if (e.target.tagName === 'A') {
61+
e.preventDefault();
62+
}
63+
})
64+
5865
return (
5966
<div ref={exampleRef}>
60-
<LivePreview className={className} />
67+
<LivePreview className={className} onClick={handleCustomRedirect}/>
6168
</div>
6269
);
6370
};

0 commit comments

Comments
 (0)
0