Fwiw, to me, this feels cleaner than somehow duplicating the selectedPet state into a useRef.
Also, while the local selectedPet variable I used is not actually needed, I feel it reads better, but YMMV, using pets.selectedPet everywhere would work just as well. First diff would be reduced to:
Aw you kept the
onChange
handler. I thought you meant to omit it and instead "listen" to the "FETCH_PET_SUCCESS" in order to update the drop-down.Fwiw, to me, this feels cleaner than somehow duplicating the
selectedPet
state into auseRef
.Also, while the local
selectedPet
variable I used is not actually needed, I feel it reads better, but YMMV, usingpets.selectedPet
everywhere would work just as well. First diff would be reduced to: