I am trying to pass an external data with the use of function inside a class component in this way for setting the property state of the following class component:
const myFunction=(val)=>{ //receive this val importing this function in another class.
const myclass = new Myclass()
myclass.setMethod(val)
}
export default Myclass extends Component{
constructor(props){
super(props);
this.state={myval:''};
}
setMethod=(val)=>{
this.setState({myval:val})
}
}
However, the value resulted inside this.state={...} always undefined, what it could be the problem?..the only solution is to pass value only by using the props?