I have a function that sits in one of my React components that's starting to get a bit long. I've decided to keep it in a separate file to keep my component a bit tidier. The issue is that the component has to refer to this
in order to get functions and states that are mapped to the props through Redux. Here's how I call it in my component:
import {myFunction} from './functions/myFunction';
handleMyFunction(event) {
myFunction(event).bind(this)
}
componentDidMount() {
this.handleMyFunction()
}
Here is the function itself in './functions/myFunction':
export const captureSnapshot = (event) => {
console.log(this.props.someState)
}
I would have thought that bind this
would make all the props available in the imported function but instead I get:
Cannot read property 'props' of undefined
when I try to run the function. How can I pass "this" to the function properly?