Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why binding is not necessary in the some classes to call functions while not in others?

Why Binding is’nt needed for the nep() to run in the image below,
enter image description here

but is needed for the hanndleSubmit() and formSubmit() to work, and throws error(onclick) if binding is removed!

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I searched for this and got to know that binding are needed if we want to pass functions or variables as props without loosing their context, but in both example, props are not passed on to another component.

>Solution :

When you want to use variables in the instance of a component like a state you must bind the instance on the method.

In the first example, you call the method, you did not bind it.

In the second example, you just bind the "formsubmit" method and it will fire when the button clicks.

it’s different between clicked={method} and clicked={method()} the first one is binding and secound one is calling .

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading