Files
DefectingCat.github.io/components/RUA/RUASandpack.tsx
Defectink 0fd635f2b2 Update post
* update algolia
2022-04-18 11:14:22 +08:00

30 lines
760 B
TypeScript

import { FC } from 'react';
import { Sandpack, SandpackProps } from '@codesandbox/sandpack-react';
import '@codesandbox/sandpack-react/dist/index.css';
import { useTheme } from 'next-themes';
import useInView from 'lib/hooks/useInView';
interface Props extends SandpackProps {}
const RUASandpack: FC<Props> = ({ ...rest }) => {
const { systemTheme, theme } = useTheme();
const currentTheme = theme === 'system' ? systemTheme : theme;
const { ref, inView } = useInView();
return (
<>
<div className="my-2 min-h-[402px]" ref={ref}>
{inView && (
<Sandpack
{...rest}
theme={currentTheme === 'dark' ? 'dark' : 'light'}
/>
)}
</div>
</>
);
};
export default RUASandpack;