Created
April 2, 2020 23:26
-
-
Save s875515/bfa3a991b0df77ae778ba71b4a8fab84 to your computer and use it in GitHub Desktop.
Facebook comments plugin with react hook on typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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