首页 > 解决方案 > 当将 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();

标签: reactjs

解决方案


推荐阅读