React Redux 同步操作返回一些代理对象而不是字符串 [英] React Redux sync action returns some Proxy object instead of string
问题描述
我有一个带有 currentAnswer
的输入:
I have an input with currentAnswer
:
<input
value={props.currentAnswer}
onChange={(text) => dispatch(onChangeAnswer(text))}
/>
调用函数onChangeAnswer
:
export function onChangeAnswer(text) {
console.log(text);
return { type: ON_CHANGE_ANSWER, data: text };
}
减速器:
export default function reduce(state = initialState, action) {
switch (action.type) {
case ON_CHANGE_ANSWER:
return assign({}, state, {
currentAnswer: action.data
});
异步操作效果很好,但是当我更改输入中的文本时,我会在控制台中看到下一个对象:
Async actions works good, but when I change text in the input I see next object in console:
{type: "ON_CHANGE_ANSWER", data: Proxy}
data: Proxy {dispatchConfig: null, _targetInst: null, …}
type: "ON_CHANGE_ANSWER"
所以,我希望在字段文本中输入 data
.
So, I want data
will be entered in field text.
我应该以某种方式发送它吗?我显然不了解这一切是如何运作的.
Should I dispatch it somehow? I obviously have a lack of understanding how all this works.
推荐答案
你得到的代理是 React SyntheticEvent
使事件在浏览器中的行为相同.您需要从原始 HTML 元素 target
访问值:
The proxy you are getting is React SyntheticEvent
which makes event behave the same across browsers. You need to access the value from target
which is original HTML Element:
<input
value={props.currentAnswer}
onChange={(event) => dispatch(onChangeAnswer(event.target.value))}
/>
顺便说一句 - 由于性能原因事件被取消 - 所以你可以't 实际上传递事件 do redux.
Btw - events get nullified for performance reasons - so you can't actually pass event do redux.
这篇关于React Redux 同步操作返回一些代理对象而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!