0

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?

Markus
  • 102
  • 9
  • you're creating react components from inside of another react component using `new`? this doesn't seem like the react way of doing things. what is the context, what are you trying to achieve? – szaman Nov 26 '21 at 19:47
  • basically i'd want pass a value retrieved from the function inside the component without using props. – Markus Nov 26 '21 at 20:10

0 Answers0