reactjs - 当将 StateValue 和 actionTypes 传递给 Search.js -> 对象不可迭代
问题描述
这是错误,我没有看到任何错误,请帮助我修复它。在此处输入图像描述
代码
import { useStateValue } from './StateProvider';
import { actionTypes } from './reducer';
function Search({ hideButtons = false }) {
const [{ }, dispatch] = useStateValue();
// In order to keep trac of input text we will use state which is how we write a vairable inside React
const [input, setInput] = useState("");
const history = useHistory();
const search = (e) => {
e.preventDefault();
console.log('you hit the search Button >>', input);
dispatch({
type: actionTypes.SET_SEARCH_TERM,
// type: 'SET_SEARCH_TERM',
term: input,
});
// do something with input ... come back and fix
history.push('/search');
};
一切似乎都很好,但这让我犯了同样的错误,
意外的空对象模式,i 行号 12:12 -> const [{ }, dispatch] = useStateValue();
解决方案
推荐阅读
- javascript - 更改 Javascript 中的窗口位置是否会杀死事件循环中的当前/即将发生的事件?
- python - 创建一个列表,其中每行在 python 中有多个字段
- python - 将模型字段 (CharField) 显示为动态 URL | 错误:以 10 为基数的 int() 的无效文字:“”
- java - 使用毫秒的 dateFormat 的 SimpleDateFormat 解析问题
- flutter - 颤振圆形图像视图
- vb.net - VB.NET 如何在 WebClient() 请求中插入数据
- pilosa - 有没有办法抵消/限制和计算 Pilosa 查询结果?
- selenium - Selenium 中的 PageFactory 类在哪里?
- r - 在存在数据安全问题的网站上实时显示不断增长的数据库的结果
- javascript - 时刻没有给我两个日期之间的天数差异