Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide more reasoning to Q12 #254

Open
qianzhong516 opened this issue May 24, 2023 · 2 comments
Open

Please provide more reasoning to Q12 #254

qianzhong516 opened this issue May 24, 2023 · 2 comments

Comments

@qianzhong516
Copy link

In What is the purpose of callback function as an argument of setState(), it was mentioned

Note: It is recommended to use lifecycle method rather than this callback function.

I never saw this saying anywhere, could you provide the reason why?

chetannada added a commit to chetannada/reactjs-interview-questions that referenced this issue May 24, 2023
@rishi9504
Copy link

Using lifecycle methods provided by the framework has several advantages over relying solely on callbacks:

  1. Better organization and separation of concerns: Lifecycle methods allow you to keep your asynchronous logic separate from the rendering logic of your component, resulting in cleaner and more maintainable code.
  2. Simplified error handling: Frameworks often provide error-handling mechanisms within their lifecycle methods, making it easier to catch and handle errors that occur during asynchronous operations.
  3. Improved control flow: Lifecycle methods ensure that asynchronous operations are performed at the appropriate times in the component's lifecycle, avoiding race conditions and other issues that can arise with manual callback management.

@Arzzam
Copy link

Arzzam commented Jun 11, 2023

Can I take this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants