2017-02-21 63 views
0

我在react-native中引入了用於搜索的Texinput。 這裏是代碼:失敗的道具類型無效的道具'值'

 constructor(props){ 
     super(props); 
     this.state = { 
      value : "", 
      items: [], 
     } 

     this.handleHeaderSearch = this.handleHeaderSearch.bind(this); 
     this.handleSearchBtn = this.handleSearchBtn.bind(this); 
     } 
     handleSearchBtn(){ 

     } 
     handleHeaderSearch(){ 
     if(!this.state.value) return; 

    } 

和:

<TextInput 
    value={this.props.value} 
    onChange = {this.props.onChange} 
    placeholder={"جستجو"} 
    blurOnSubmit={false} 
    style={{flex:0.9}} 
    returnKeyType="done" 
/> 

每當我在文字輸入輸入後運行Android,我看到這樣的警告:

「警告未能道具類型無效提供給TextInput的類型'對象'的屬性'值',預期'字符串'「

+0

當你改變價值時,你可以發佈一個代碼片段嗎? –

+0

它正常工作,只有警告 –

回答

3

您正在將值存儲在this.state.value(或至少看起來是您的意圖),但您將this.props.value傳遞給您的TextInput。

如果你打算通過this.props.value到TextInput,這將有助於知道什麼是傳遞到此組件(一級)。

相關問題