Skip to content

Instantly share code, notes, and snippets.

@MinthangML
Created December 21, 2020 05:05
Show Gist options
  • Save MinthangML/6ce80bb746ee596d4e9c071fe4a1fd00 to your computer and use it in GitHub Desktop.
Save MinthangML/6ce80bb746ee596d4e9c071fe4a1fd00 to your computer and use it in GitHub Desktop.
The right way to modify ref
import React, { useRef } from "react";
const RenderCounter = () => {
const counter = useRef(0);
useEffect(() => {
// component ကို re-render လုပ်ပြီးတဲ့အချိန်တိုင်း counter က increase လုပ်နေပါလိမ့်မည်။
counter.current = counter.current + 1;
});
return (
<h1>{`The component has been re-rendered ${counter} times`}</h1>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment