@@ -163,28 +163,28 @@ The widget modifies the DOM directly, so you must use `useEffect` to initialize
163163``` jsx
164164import { useEffect } from ' react' ;
165165
166- // 1. Import the CSS (or copy the contents to your CSS file)
167- // import './gh.css';
168-
169166const ContributionGraph = ({ username }) => {
170167 useEffect (() => {
171- // 2. Load the script dynamically
168+ // Add CSS
169+ const link = document .createElement (' link' );
170+ link .rel = ' stylesheet' ;
171+ link .href = ' https://github-contribution-graph.netlify.app/assets/css/gh.css' ;
172+ document .head .appendChild (link);
173+
174+ // Add Script
172175 const script = document .createElement (' script' );
173- script .src = " https://github-contribution-graph.netlify.app/assets/js/gh.js" ;
176+ script .src = ' https://github-contribution-graph.netlify.app/assets/js/gh.js' ;
174177 script .async = true ;
175178 document .body .appendChild (script);
176179
177180 return () => {
181+ // Cleanup on unmount
182+ document .head .removeChild (link);
178183 document .body .removeChild (script);
179- }
184+ };
180185 }, []);
181186
182- return (
183- < div className= " main-container" >
184- {/* Your wrapper elements... */ }
185- < div id= " gh" data- login= {username}>< / div>
186- < / div>
187- );
187+ return < div id= " gh" data- login= {username}>< / div> ;
188188};
189189
190190export default ContributionGraph ;
@@ -194,24 +194,36 @@ export default ContributionGraph;
194194
195195``` vue
196196<template>
197- <div class="main-container">
198- <div id="gh" :data-login="username"></div>
199- </div>
197+ <div id="gh" :data-login="username"></div>
200198</template>
201199
202200<script setup>
203- import { onMounted } from 'vue';
201+ import { onMounted, onUnmounted } from 'vue';
204202
205203const props = defineProps({
206204 username: String
207205});
208206
207+ let link, script;
208+
209209onMounted(() => {
210- const script = document.createElement('script');
211- script.src = "https://github-contribution-graph.netlify.app/assets/js/gh.js";
210+ // Add CSS
211+ link = document.createElement('link');
212+ link.rel = 'stylesheet';
213+ link.href = 'https://github-contribution-graph.netlify.app/assets/css/gh.css';
214+ document.head.appendChild(link);
215+
216+ // Add Script
217+ script = document.createElement('script');
218+ script.src = 'https://github-contribution-graph.netlify.app/assets/js/gh.js';
212219 script.async = true;
213220 document.body.appendChild(script);
214221});
222+
223+ onUnmounted(() => {
224+ if (link) document.head.removeChild(link);
225+ if (script) document.body.removeChild(script);
226+ });
215227</script>
216228```
217229
0 commit comments