I am building an application with a lot of screens (components) each one has some methods such as save, add, delete, redo, view, and other functions. every function of them has a lot of code in it.
now I have declared these functions outside my components and call them from my methods attached to the screen component so I can access them. when I call them I pass this keyword as an argument so I can access the state and props from these functions.
I did this to be able to share this logic across the components.
now my question: Is this a best practice? if yes what is the best way to do this if not what should I do instead
note I am using react
You can use a Custom Hook that contains all the re-used logic you have if that what's you want.
Read more about this feature here: https://reactjs.org/docs/hooks-custom.html https://www.w3schools.com/react/react_customhooks.asp