-1

Sorry for the noob question in advance. I have got a button, and I have a function in a different folder which I am trying to execute... I have tried to import the function from my other folder however it does not seem to be exceuting...How do I call this correctly?

ModalTopBar.js

import LineageContent from  '../../ReusableComponents/Lineage/LineageContent'



              <Button text='Get SQL' onClick={LineageContent.onHandle} />
              

LineageContent:

  const onHandle = () => {
    console.log('clicked')
  }

File path to where I am importing lineage content if it helps:

enter image description here

stack5 flow
  • 65
  • 1
  • 5
  • I have an answer to a similar question elsewhere that should be helpful: [Correct way to share functions between components in React](https://stackoverflow.com/a/51661103/2430549) And if that's not enough, I have another! [How to set one component's state from another component in React](https://stackoverflow.com/a/62365670/2430549) – HoldOffHunger Nov 16 '20 at 02:39

1 Answers1

0

First of all lets clear that the Components in reactjs is reusable so you can't simply import a new instance then use a nested function from this component

if the Component that you want to use a nested function is parent or even ancestor to the current component then you should props and pass the function address throw it else you should use something like redux and save this function address in a store then use wherever you want this is a bad practice to use redux

Khaled Ahmed
  • 1,074
  • 8
  • 21