- Accessing DOM Elements with Refs
- Managing Values with Refs
- Exposing API Functions from Components
- Detaching DOM Rendering from JSX Structure with Portals
- run
npm install
- run
npm run dev
- create
README.md
- use
useState()
and two-way-binding inPlayer.jsx
- replace
useState()
withuseRef()
inPlayer.jsx
because it is more convenient
- use
useRef()
to clear the input inPlayer.jsx
- create
TimerChallenge.jsx
component - output
<TimerChallenge />
components inApp.jsx
- use
useState()
to set a timer inTimerChallenge.jsx
- render UI dynamically
- use
useRef()
inTimerChallenge.jsx
to store thetimer
value without resetting it when the component is reexecuted
- create
ResultModal.jsx
component - output the
<ResultModal />
component inTimerChallenge.jsx
- reach out the dialog in
ResultModal
fromTimerChallenge.jsx
with help ofuseRef()
- forward the ref defined in
TimerChallenge.jsx
to the dialog element inResultModal.jsx
with help of theforwardRef
function - use this dialog in
TimerChallenge.jsx
- detach the
TimerChallenge.jsx
component from thedialog
element from the ``ResultModal.jsxcomponent with help of
useImperativeHandle()`
- measure how much time is left on an ongoing basis with
setInterval()
instead ofsetTimeout
inTimerChallenge.jsx
- use
clearInterval()
instead ofclearTimeout()
- forward the correct information to the modal by replacing the
result
prop with theremainingTime
prop - use the
remainingTime
prop to calculate the score or find out if the user lost inResultModal.jsx
- add a
handleReset
function to reset the remaining time correctly - trigger the
handleReset()
function through aonReset
prop fromResultModal.jsx
- calculate the score in
ResultModal.jsx
- output the score dynamically
- add the built-in
onClose
prop to the<dialog>
element and bind it to theonReset
prop value
- use the
createPortal()
function imported fromreact-dom
on the<dialog>
element inResultModal.jsx
- attach the modal to the
<div>
with anid
ofmodal
inindex.html