How to access a variable defined in a react component from another js file?
I have a react component like follows:
App.js
class App extends React.Component {
constructor(props) {
super(props);
this.name = "Rajkiran";
}
}
I have a utils file like below
utils.js
export fun1() {
//I want to access the "name" value defined in App.js here
}
export fun2() {
}
fun1(this.name). There's ways to get around it, but if your function depends on it, its a good practice to make that clear by requiring it as a parameter.