首页 > 解决方案 > 无法呈现正确的状态,react-native - TextInput(输入是粘性的 - 不会更新,但会加载正确的数据)

问题描述

TextInput 没有正确更新,我不知道为什么不正确。据我所知,状态方面的一切都是正确的,而且我看不到它的连接方式有任何错误。

我没有看到我错过了什么。

应用程序.js

const [receivingState,setReceivingState]=useState({
  barcodes:[
    {code:"",validState:VALID_STATES[0]},
    {code:"",validState:VALID_STATES[0]},
    {code:"",validState:VALID_STATES[0]},
    {code:"",validState:VALID_STATES[0]},
    {code:"",validState:VALID_STATES[0]},
    {code:"",validState:VALID_STATES[0]},
    {code:"",validState:VALID_STATES[0]},
  ]
})



const HandleChange=(property,value,number)=>{
  setReceivingState(prev=>{
    prev.barcodes[number][property]=value;
    return prev;
  })
}

<Route path="/receiving" render={props=>(<ReceivingWindow props={props} slice={receivingState} handleChange={HandleChange}/>)} />

接收窗口


const slice = props.slice;
const barcodes = slice.barcodes;
const HandleChange = props.handleChange;

//in the return
{barcodes.map((x,i)=><ReceivingBarcode code={x.code} key = {`barcode${i}`} number={i} validState={x.validState} handleChange={HandleChange}/>)}


接收条码

const code = props.code;


const updateText=(text)=>{
    console.log(text,"text is!!!!");
    handleChange("code",text,props.number);
    console.log("text => ",text);
}

//in the return
<TextInput style={STYLE.input} onChangeText={(e)=>updateText(e)} value={code} name="barcodeinput"></TextInput>



标签: javascriptreactjsreact-nativeonchange

解决方案


推荐阅读