example for react use
See original GitHub issuehi @jdanyow,
Your work is awesome ! Just want to contribute this example made with JSX (react) cause it took me some time especially with the custom attributes for script tag.
import React, {Component} from "react";
export default class Comments extends Component {
componentDidMount () {
let script = document.createElement("script");
let anchor = document.getElementById("inject-comments-for-uterances");
script.setAttribute("src", "https://utteranc.es/client.js");
script.setAttribute("crossorigin","anonymous");
script.setAttribute("async", true);
script.setAttribute("repo", "[ENTER REPO HERE]");
script.setAttribute("issue-term", "pathname");
script.setAttribute( "theme", "github-light");
anchor.appendChild(script);
}
render() {
return (
<div id="inject-comments-for-uterances"></div>
);
}
}
Might be useful. And of course I’m gonna use your tool ! (I use gatsby js)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:37
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Introducing Hooks - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. This new...
Read more >react-use examples - CodeSandbox
Learn how to use react-use by viewing and forking example apps that make use of react-use on CodeSandbox. ; downshift-examplesExamples of using downshift....
Read more >React Tutorial - W3Schools
React is used to build single-page applications. React allows us to create reusable UI components. Start learning React now ❯. Learning by Examples....
Read more >The Guide to Learning React Hooks (Examples & Tutorials)
Let's learn what it takes to create a custom React Hook as well as all the rules we must keep in mind when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For a more concise approach to it, this is how I just did it on my repo:
This should be safe - you get the DOM elem, this gets invoked once on mount, and once with
null
on unmount.Using a hook:
Usage:
I’ve written an article which also shows how to lazy load, so that the comments show up when user reaches to the end of the page, (or wherever your comments are on the page), using Intersection Observer API.