使用react-native形成onSubmit

Jos*_*gon 1 forms onsubmit react-native

抱歉,如果这是一个基本问题,但我似乎无法找到一些东西来替换我的react-native项目中html中的“form”标签,所以我不知道在哪里调用我的“onSubmit”来发送我的搜索请求,因为react-native中的'Form'标签不接受onSubmit事件。那么我会用什么呢?这是我的代码,这样你就知道它是什么样的

class SearchBar extends Component{
state = { term: '' }

  onFormSubmit(e) {
     e.preventDefault();
     console.log(this.state.term)
  }
 render(){
   return (
     <View style={styles.viewStyle}>
      <Text style=
       {styles.textStyle}>Search For Sick Pics.</Text>

  //so right here is what i dont know what to wrap my Textinput in, like in a react app we would wrap it in the "<form>" tag

        <TextInput 
        style={styles.inputStyle}
        type='text'
        placeholder='Search for Sick pics'
        value = {this.state.term}
        onChange = {event => this.setState({ term: event.target.value })}
        />   

  </View>
  )
 }
}
Run Code Online (Sandbox Code Playgroud)

这是我的主要组件

     class MainPage extends Component {
      state = { images: [] }

    onSearchSubmit = (term) => {
      axios.get('https://api.unsplash.com/search/collections', {
       params: { query: term },
       headers: {
     Authorization: 
     'Client-ID jfkjasdhlkfjskdljfksdjfljasfasdj;fjaskdj'

    }
  }).then((response) => {
   console.log(response)
  })
}

 render() {
   return (
     <View>
         <SearchBar onSubmitEditing={this.onSearchSubmit}/>

     </View>
)
Run Code Online (Sandbox Code Playgroud)

} }

kiv*_*vul 5

尝试这个:

<TextInput 
  style={styles.inputStyle}
  type='text'
  placeholder='Search for Sick pics'
  value = {this.state.term}
  onChange = {event => this.setState({ term: event.target.value })}
  onSubmitEditing = {() => console.log(this.state.term)}
/>
Run Code Online (Sandbox Code Playgroud)

或者您也可以调用“onFormSubmit”函数