Buğrahan Öz
Buğrahan Öz

Reputation: 33

How to change axios url?

  constructor(props) {
    super(props);
    this.state = {
      isLoading: true,
      search:'',
    };
  }

  componentDidMount(){
    var url = 'url='+this.state.search;
    axios.get(url)
      .then(response =>this.onResponse(response.data));
  }

  onResponse(gelen){
    this.setState({
      isLoading:false,
      veri:gelen,
    });
    console.log(this.state.veri);
  }

  render() {
    if (this.state.isLoading) {
      return (
        <View style={{flex: 1, paddingTop: 20}}>
          <ActivityIndicator />
        </View>
      );
    }
    return(
      <View style={styles.container}>
        <TextInput
          style={{height: 40, borderColor: 'gray', borderWidth: 1}}
          onChangeText = {(search) => this.setState({search})}
          placeholder="Welcome">
        </TextInput> 
      </View>
    );
  }

React Native Search is change but url do not change how do change or update url ? I wanted to make a search page, and I tried something like this, but I could not add the data entry I made after the data came in at the end of the url.

Upvotes: 1

Views: 650

Answers (1)

Vivek Doshi
Vivek Doshi

Reputation: 58573

All you need to do is, fire set search state and also fire the axios

You can do it like :

<TextInput
    style={{height: 40, borderColor: 'gray', borderWidth: 1}}
    onChangeText = {(search) => this.searchData(search)}
    placeholder="Welcome">
</TextInput> 

searchData(search) {
    this.setState({search});
    var url = 'url='+search;
    axios.get(url).then(response => this.onResponse(response.data));
}

Upvotes: 1

Related Questions