@@ -12,7 +12,7 @@ import { useEffect } from "react";
1212
1313import "./styles.css" ;
1414
15- const renderMatrix = ( ref ) => {
15+ const renderMatrix = ( ref , color ) => {
1616 let canvas = ref . current ;
1717 let context = canvas . getContext ( "2d" ) ;
1818
@@ -38,7 +38,7 @@ const renderMatrix = (ref) => {
3838 context . fillStyle = "rgba(0, 0, 0, 0.05)" ; // black w a tiny bit of alpha
3939 context . fillRect ( 0 , 0 , canvas . width , canvas . height ) ;
4040
41- context . fillStyle = "#0F0" ; // pure green
41+ context . fillStyle = color ? color : "#0F0" ;
4242 context . font = fontSize + "px monospace" ;
4343
4444 for ( let i = 0 ; i < rainDrops . length ; i ++ ) {
@@ -57,17 +57,18 @@ const renderMatrix = (ref) => {
5757 rainDrops [ i ] ++ ;
5858 }
5959 } ;
60-
61- return ( ) => {
62- setInterval ( render , 30 ) ;
63- } ;
60+ return render ;
6461} ;
6562
6663const MatrixRainingLetters = ( props ) => {
6764 const ref = useRef ( ) ;
6865 const keyName = "mrl-" + props . key ;
6966 const thisClassName = "mrl-container " + props . custom_class ;
70- useEffect ( ( ) => renderMatrix ( ref ) ) ;
67+ useEffect ( ( ) => {
68+ const render = renderMatrix ( ref , props . color ) ;
69+ const intervalId = setInterval ( render , 30 ) ;
70+ return ( ) => clearInterval ( intervalId ) ;
71+ } , [ props . color ] ) ;
7172
7273 return (
7374 < React . Fragment >
0 commit comments