Reputation:
I want to separate my function with hook because i have a lot of in one file....
example of code:
const collectOrganisationUnitNode = useCallback((treeData) => {
// someLogic
}, []);
const handleCancelClick = useCallback(() => {
.../some logic
}, [hideModal, selected, multiselect, tree]);
I want to remove from index.js and set to another file then just import and using inside index.js
is that possible ?
Upvotes: 0
Views: 1711
Reputation: 21
You could make a custom hook that returns these functions.
const customHook = () => {
const collectOrganisationUnitNode = useCallback((treeData) => {
// someLogic
}, []);
const handleCancelClick = useCallback(() => {
//some logic
}, [hideModal, selected, multiselect, tree]);
return {
collectOrganisationUnitNode,
handleCancelClick
}
};
Then used like so inside your component
const { collectOrganisationUnitNode, handleCancelClick } = customHook();
Upvotes: 2