-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathssr.tsx
More file actions
62 lines (51 loc) · 1.37 KB
/
Copy pathssr.tsx
File metadata and controls
62 lines (51 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { clsx } from 'clsx';
import CSSMotion, { genCSSMotion } from 'rc-motion';
import React from 'react';
import { hydrateRoot } from 'react-dom/client';
import ReactDOMServer from 'react-dom/server';
import './basic.less';
const ServerCSSMotion = genCSSMotion(false);
const onCollapse = () => ({ height: 0 });
interface MotionAppearProps {
supportMotion: boolean;
}
const MotionAppear = ({ supportMotion }: MotionAppearProps) => {
const Component = supportMotion ? CSSMotion : ServerCSSMotion;
return (
<Component
motionName="transition"
leavedClassName="hidden"
motionAppear
onAppearStart={onCollapse}
>
{({ style, className }, ref) => (
<div
ref={ref}
className={clsx('demo-block', className)}
style={style}
/>
)}
</Component>
);
};
const App = () => {
const ssr = ReactDOMServer.renderToString(
<MotionAppear supportMotion={false} />,
);
React.useEffect(() => {
const div = document.createElement('div');
document.body.appendChild(div);
div.innerHTML = ssr;
const root = hydrateRoot(div, <MotionAppear supportMotion />);
return () => {
root.unmount();
document.body.removeChild(div);
};
}, []);
return (
<div>
<textarea value={ssr} style={{ width: '100%' }} rows={5} readOnly />
</div>
);
};
export default App;