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

Asked

Viewed 1,701 times

-1

I’m new here at the forum and I’m studying Act 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 dropdown list using the map, but I want to update this list every time I call the search functionTerm() in Home.js.

How do I do that?

  • But the Home is a child component of App ? I don’t see him in the render.

  • Enter the code of your entire Home component, if not to know which component is child, which is parent.

1 answer

-1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.