Skip to content

Instantly share code, notes, and snippets.

@s875515
Created April 2, 2020 23:26
Show Gist options
  • Save s875515/bfa3a991b0df77ae778ba71b4a8fab84 to your computer and use it in GitHub Desktop.
Save s875515/bfa3a991b0df77ae778ba71b4a8fab84 to your computer and use it in GitHub Desktop.
Facebook comments plugin with react hook on typescript
import React, { useEffect, useRef } from "react";
import { has } from "lodash/object";
import { SingletonRouter } from "next/router";
interface IProps {
router: SingletonRouter;
}
const FbComment = ({ router }: IProps) => {
const fbRef = useRef(null);
useEffect(() => {
if (global.document && has(global.window, "FB")) {
global.FB.XFBML.parse(fbRef.current);
}
}, []);
return (
<div ref={fbRef}>
<div
className="fb-comments"
data-href={`${global.window.location.origin}${router.asPath}`}
data-width="100%"
data-numposts="5"
style={{ width: "100%" }}
/>
</div>
);
};
export default FbComment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment