https://github.com/neomaxzero/usedisqus
React hook recipe to import comments from disqus
https://github.com/neomaxzero/usedisqus
Last synced: 4 months ago
JSON representation
React hook recipe to import comments from disqus
- Host: GitHub
- URL: https://github.com/neomaxzero/usedisqus
- Owner: neomaxzero
- Created: 2019-11-24T10:19:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-24T10:42:01.000Z (over 6 years ago)
- Last Synced: 2025-02-08T01:27:51.478Z (over 1 year ago)
- Size: 2.93 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# useDisqus
React hook recipe to import comments from disqus
## Steps
1. Copy this snippet.
2. Use it in your project.
## Recipe
```javascript
// Comments.js
import React, { useEffect } from 'react'
const Comments = ({ fullUrl, id }) => {
useEffect(() => {
const DISQUS_SCRIPT = 'disq_script'
const sd = document.getElementById(DISQUS_SCRIPT)
if (!sd) {
var disqus_config = function() {
this.page.url = fullUrl
this.page.identifier = id
}
const d = document
const s = d.createElement('script')
s.src = 'https://m4x-io.disqus.com/embed.js'
s.id = DISQUS_SCRIPT
s.async = true
s.setAttribute('data-timestamp', +new Date())
d.body.appendChild(s)
} else {
window.DISQUS.reset({
reload: true,
config: disqus_config,
})
}
}, [])
return
}
export default Comments
```
## Use
```javascript
// Post.js
import React from 'react';
import Comments from './Comments';
const Post = () => (
<>
>
);
export default Post;
```
## Future (if someone give me a star)
- Create real hook to import.