react should write method in a functional component or outside functional component

Solutions on MaxInterview for react should write method in a functional component or outside functional component by the best coders in the world

showing results for - "react should write method in a functional component or outside functional component"
Catherine
03 Apr 2017
1In most cases you should declare the functions outside of the component function
2so you declare them only once and always reuse the same reference. When you 
3declare the function inside, every time the component is rendered the function 
4will be defined again.
5
6There are cases in which you will need to define a function inside the component
7to, for example, assign it as an event handler that behaves differently based on
8the properties of the component. But still you could define the function outside
9Ball and bind it with the properties, making the code much cleaner and making 
10the update or draw functions reusable.