immerjs / use-immer

Use immer to drive state with a React hooks
MIT License
4.04k stars 92 forks source link

using updateState method in hook requires updateState method as a dependency ? #67

Closed jiangyh1024 closed 3 years ago

jiangyh1024 commented 3 years ago

using useState will not require it to be a dependency

is there any way to avoid this warning??

or do I have to include the updateState method to the dependency array?

image

image

mweststrate commented 3 years ago

yes, just include it in de dep array. The ref is stable but React / lint doesn't know that (unlike setState which is a hardcoded exception)

On Mon, Oct 26, 2020 at 8:08 AM jiangyh1024 notifications@github.com wrote:

using useState will not require it to be a dependency ?

is there any way to avoid this warning??

or do I must include the updateState method to the dependency array?

[image: image] https://user-images.githubusercontent.com/34930870/97147950-48999700-17a5-11eb-8aa2-3b13be672b03.png

[image: image] https://user-images.githubusercontent.com/34930870/97147993-5b13d080-17a5-11eb-99a1-1a59e76b3ed7.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/immerjs/use-immer/issues/67, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBBSXTFIILKD6LAYQFTSMUU6BANCNFSM4S7BFXJA .

jiangyh1024 commented 3 years ago

OK, thanks a lot