How do I update a component of another class in React?

0

I'm new here in the forum and I'm studying react and I came across a question ..

I have the following files:

App.js

    class App extends Component {

      constructor(props) {
          super(props)
          this.state = {
            historico:[],
            isLoading: false
          }
          this.loadData = this.loadData.bind(this)
      }

      loadData() {
        this.setState({ isLoading: true })
        functions.loadHistorico()
          .then((res)=>{
            this.setState({historico: res}),
            console.log(this.state.historico)
          })
      }

      render() {
          return (
              <li className="dropdown">
                <a href="#" className="dropdown-toggle" data-toggle="dropdown"> Histórico <span className="caret"></span> </a>
                <ul className="dropdown-menu"> 
                  {this.state.historico.map(this.renderHistorico)}
                </ul>
              </li>
           )
      }


    }

and Home.js

class Home extends Component {
      //>>> aqui tem o constructor(props) {}  e componentDidMount() {} etc...

      pesquisarTermo() {
        functions.salvarHistorico(this.refs.termo.value)
        //app.loadData()  <=====
      }
 }

I'm creating a list of a dropdown using the map, however I want to update this list every time I call the searchTermo () function in Home.js.

How do I do this?

    
asked by anonymous 11.05.2018 / 00:50

1 answer

0

You should reference the App Daughter class within the parent class render.

import App from ../../App

class Home extends Component {
    render(){
        <App/>
    }
}

After that, here is an example of how to call the method: link

    
18.05.2018 / 17:04