24
loading...
This website collects cookies to deliver better user experience
<button disabled={count === 3}>Button</button>
When you want a component to “remember” some information, but you don’t want that information to trigger new renders, you can use a ref—it’s like a secret “pocket” for storing information in your component!
<button disabled={count.current === 3}>Button</button>
Parent
state, it renders both Parent
and Component
. And when Component
renders, React executes the condition and disables a button.<button disabled={count.current === 3}>Button</button>
Component
.butttonStatus
only when the button clicked the third time.<button
disabled={buttonStatus === 'disabled'}
onClick={() => {
count.current++
if (count.current === 3) {
setButtonStatus('disabled')
}
}}
>