Skip to content
Advertisement

Is it bad practice to accept setState as a function parameter in React?

Basically, before uploading an image to the firebase, I’m trying to control the input as:

JavaScript

which I call the above method from /lib/controlThumbnail.js to:

JavaScript

so, this is now works correctly, but I wonder if this is the good way of doing it? Or should I put the control method inside the component and never give setState as parameter?

Advertisement

Answer

It is subjective. Personally, I think the controlThumbnail function is not the right place to make that abstraction. In here, you are really only providing validation. You don’t need to give it the responsibility to validate AND set some state.

You could create a pure validation function, and just use the return of this to update the state in your Signup component:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement