Skip to content

Instantly share code, notes, and snippets.

@MinthangML
Created December 21, 2020 05:02
Show Gist options
  • Save MinthangML/86c93f1326cfaa734a13433ad4fc0bc8 to your computer and use it in GitHub Desktop.
Save MinthangML/86c93f1326cfaa734a13433ad4fc0bc8 to your computer and use it in GitHub Desktop.
Modify Ref in Render Phase
import React, { useRef } from "react";
const RenderCounter = () => {
const counter = useRef(0);
// "Render phase" မှာ ref ရဲ့ value ကို update လုပ်မယ်ဆိုရင်
// အဲဒီ value က တစ်ကြိမ်ထက်မက increment လုပ်နိုင်ပါတယ်။
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