我是反应的新手,目前使用上下文API,我正在尝试从表单中的用户输入中获取国家名称,然后发送回上下文,并且在上下文中我使用Concercentdidmount调用API并显示数据,当用户输入时,它保存数据警报它,但随后突然出现该错误。这是我的表单文件。import React, { useState } from 'react'import { Consumer } from '../../context';import Spinner from '../spinner';function Country() { const [name, setName] = useState(''); // function Submit (e, dispatch){ e.preventDefault(); alert(`this form is submited ${name}`) dispatch({type: 'SELECT_COUNTRY', payload: name}); setName(''); } return ( <Consumer> { value =>{ if (!value.chart.length){ return <Spinner/> } else{ // setCountry(value.countries) const { dispatch } = value; console.log('coming from dispatch',dispatch) </Consumer> )}
添加回答
举报
0/150
提交
取消