1👍
I think what you want to do is to reuse logic from one component to another. I’ll suggest you use composable. This isn’t really gonna be an easy route for a beginner but it’s the best solution for you.
Aside composible, you can check out mixins and renderless components.
I’ll suggest you experiment with mixin but take note this is no longer the way forward. Take some time to learn how composables work. If you have background with React hooks it’s gonna be straightforward.
And finally, if the logic in component A doesn’t have a thing to do with states and props, I’ll suggest you put all the logic in a util function you can import/reuse between the two components or more.
Take care.
0👍
You can extract out the function into a separate file. Include the function for the component you would like to use. If the function has any dependency on component data, you would pass it in as a parameter
// Utility.js
export function toLower(name) {
return name.toLowerCase()
}
// Component A
import { toLower } from './Utility';
...