src/App.js
//this will run if the props or state changes, we will use this is the query param is updated
this will run if the props or state changes, we will use this is the query param is updated
this will run if the props or state changes we will use this is the query param is updated
async componentDidUpdate(prevProps, prevState) {
    if (this.state.searchQuery !== prevState.searchQuery) {
      if (this.state.searchQuery === '') {
        await fetch('http://localhost:3001/emails')
          .then(response => response.json())
          .then(data => this.setState({emailList: data, emailSelected: false}));
        } else {
          await fetch(`http://localhost:3001/search?query=${this.state.searchQuery}`)
            .then(response => response.json())
            .then(data => this.setState({emailList: data, emailSelected: false}));
        }
    }
  }
async componentDidUpdate ( prevProps , prevState ) { if ( this . state . searchQuery !== prevState . searchQuery ) { if ( this . state . searchQuery === '' ) { await fetch ( 'http://localhost:3001/emails' ) . then ( response => response . json ( ) ) . then ( data => this . setState ( { emailList : data , emailSelected : false } ) ) ; } else { await fetch ( ` ${ this . state . searchQuery } ` ) . then ( response => response . json ( ) ) . then ( data => this . setState ( { emailList : data , emailSelected : false } ) ) ; } } }
this will run if the props or state changes, we will use this is the query param is updated
this will run if the props or state changes we will use this is the query param is updated