SkyeYoung commented on code in PR #1115:
URL: https://github.com/apache/apisix-website/pull/1115#discussion_r878870788


##########
website/src/components/UI/Affix.tsx:
##########
@@ -0,0 +1,99 @@
+import type { CSSProperties, ReactNode, FC } from 'react';
+import React, { useState, useEffect } from 'react';
+import styled from 'styled-components';
+
+import { getDomStyle } from '../../utils';
+
+interface Props {
+  style: CSSProperties;
+  children: ReactNode;
+}
+
+const AffixContent = styled.div`
+`;
+
+const getPositionStyle = (
+  hasCssSticky: boolean,
+  defaultStyles: CSSProperties = {},
+):CSSProperties => {
+  const { width } = defaultStyles;
+  const positionStyle: CSSProperties = hasCssSticky ? {
+    position: 'sticky',
+    marginLeft: `-${width}px`,
+    display: 'inline-block',
+    float: 'left',
+  } : {
+    position: 'absolute',
+  };
+
+  return {
+    ...positionStyle,
+    ...defaultStyles,
+  };
+};
+
+const Affix: FC<Props> = (props) => {
+  const { style, children } = props;
+  const [hasCssSticky, SetHasCssSticky] = useState(true);
+  useEffect(() => {
+    SetHasCssSticky(CSS.supports('position', 'sticky'));
+  });

Review Comment:
   You may need the help of this document 
https://reactjs.org/docs/hooks-reference.html#timing-of-effects.
   
   Since I didn't write most of the original code, and I haven't tried to 
improve them, many of them are negative examples, so please don't learn how 
they are written.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to