To make it clear... I have a submit button and when the user hits it i want to execute some functions that fetch some date and display some results. I can create those functions inside one component but it will be so big and i want to avoid that. So how can i write those functions on a separate js file and import them on the component that calls them ?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
The solution is just as you said here, wirte the function in a separate file and import it in the two component you want to use it and then use it. And you do it like any other function, just use import/export keyword.
Or you can go even one step further and make it a custom hook
Thanks fro the reply.. I think useContext will be a solution here. In this case, i want the functions to fetch some api and call them on a onClick att inside a input..