react-utterances-github-comments
Version:
A lightweight React wrapper for Utterances GitHub comment system
1 lines • 1.05 kB
JavaScript
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useEffect,useState}from"react";const GithubComments=({repo:e,issueTerm:t,theme:s="github-light",label:r,titleText:n="Comentarios",loadingText:i="Cargando comentarios...",className:o=""})=>{const[c,a]=useState(!0);return useEffect((()=>{if("undefined"==typeof window)return;const n=setTimeout((()=>{const n=document.getElementById("utterances-thread");if(!n)return;n.innerHTML="";const i=document.createElement("script");i.src="https://utteranc.es/client.js",i.setAttribute("repo",e),i.setAttribute("issue-term",t),i.setAttribute("theme",s),i.setAttribute("crossorigin","anonymous"),i.async=!0,r&&i.setAttribute("label",r),i.onload=()=>a(!1),i.onerror=()=>{a(!1),console.error("Error loading Utterances script")},n.appendChild(i)}),0);return()=>clearTimeout(n)}),[e,t,s,r]),_jsxs("section",{className:o,children:[_jsx("h3",{style:{textAlign:"center"},children:n}),c&&_jsx("p",{style:{textAlign:"center"},children:i}),_jsx("div",{id:"utterances-thread"})]})};export default GithubComments;