Pass a state from one class to another class in REACT JS.

github logo ・1 min read

Hello, I need to pass a state from one class to another class.

Can I do it with a callback?

You help me?

Example:
class SearchNav extends Component {
constructor(props) {
super(props);
this.state = {
q: '',
param: {},
getData: []
};
}

getDataSearch = () => {
fetch(url + ${this.state.q})
.then(res => res.json())
.then(data => {
this.setState({ getData: data.hits });
console.log(this.state.getData);
})
.catch(Error => {
console.log(Error);
});
};
...
I need pass state =>'getData' to other class.

twitter logo DISCUSS
Classic DEV Post from May 13

What cool ideas have you seen for integrating new team members?

I came across this tweet from a couple days ago and it really struck a chord with...

CristianCuartas profile image
In the process of learning