javascript - 无法呈现正确的状态,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>
解决方案
推荐阅读
- performance - LISP 对象没有更多空间错误 wxMaxima
- javascript - 在 POST Express 中使用隐藏输入
- cmake - 在 Windows 10 上使用 CMake 编译 Assimp
- excel - 自动调整行然后添加高度
- augmented-reality - Google Cloud Anchor 和 Microsoft Azure Spatial Anchor 的区别
- python - 设置坐标原点 plotly python
- terraform - Template.tf 和 user_data.yaml.tpl- 通过 list 类型的变量循环
- reactjs - PropType 声明函数,值未定义
- javascript - 如果语句 JavaScript,数学在我的 else 语句中不起作用我做错了什么?
- php - 如何使用 PHP 函数使用 PDO 连接到 MySQL