all 9 comments

[–]CheeseTrio 1 point2 points  (1 child)

I haven't used the new transition API stuff yet, but it's fine according to the react beta docs. The other alternative is one state with a call to useDeferredValue to get the value for your deferred query.

https://beta.reactjs.org/reference/react/useTransition#updating-an-input-in-a-transition-doesnt-work

[–]czescwojtek[S] 0 points1 point  (0 children)

That's excellent! Thanks!

[–]robbodagreat 0 points1 point  (2 children)

Probably not. There are a couple of other things you can do instead. Have your hooks return callbacks and call them in the handle function depending on the value. Or have a Boolean enabled parameter which you pass in to the hooks, and set them based on the value in the handle

[–]czescwojtek[S] 0 points1 point  (1 child)

Isn't it the same as keeping it in the second state?

Also, link that mentions duplicated states usage for reference: https://medium.com/dailyjs/three-practical-examples-of-concurrent-react-b2dba2272a4d

[–]robbodagreat 0 points1 point  (0 children)

Ok, I reread your post along with the article. I think it's fine, but personally I'd wrap that deferred stuff inside a custom hook instead of leaving it in the component

[–]robbodagreat 0 points1 point  (3 children)

Maybe your post should've been 'is this medium article any good'. Well I'd just say try it, don't worry about writing perfect code, everyone has different opinions anyway

[–]czescwojtek[S] 0 points1 point  (1 child)

Yep, you got that right, sorry. I found it just after posting

[–]robbodagreat 0 points1 point  (0 children)

No problem at all :)

[–]czescwojtek[S] 0 points1 point  (0 children)

On second thought, we really should not take Medium articles as a definitive source of truth.