React Hooks-Axios未捕获(承诺)错误:网络错误

时间:2020-06-26 16:00:33

标签: reactjs api axios react-hooks

[已解决]我正在尝试使用react钩子重构我已经在react中拥有的代码。我收到此错误:

xhr.js:178 GET https://api.chucknorris.is/jokes/search?query= net::ERR_NAME_NOT_RESOLVED
dispatchXhrRequest @ xhr.js:178
xhrAdapter @ xhr.js:12
dispatchRequest @ dispatchRequest.js:52
Promise.then (async)
request @ Axios.js:61
Axios.<computed> @ Axios.js:76
wrap @ bind.js:9
onSearchSubmit @ App.js:15
(anonymous) @ App.js:21
commitHookEffectListMount @ react-dom.development.js:19731
commitPassiveHookEffects @ react-dom.development.js:19769
callCallback @ react-dom.development.js:188
invokeGuardedCallbackDev @ react-dom.development.js:237
invokeGuardedCallback @ react-dom.development.js:292
flushPassiveEffectsImpl @ react-dom.development.js:22853
unstable_runWithPriority @ scheduler.development.js:653
runWithPriority$1 @ react-dom.development.js:11039
flushPassiveEffects @ react-dom.development.js:22820
(anonymous) @ react-dom.development.js:22699
workLoop @ scheduler.development.js:597
flushWork @ scheduler.development.js:552
performWorkUntilDeadline @ scheduler.development.js:164
createError.js:16 Uncaught (in promise) Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:83)

这是我正在使用的API: https://api.chucknorris.io/

使用自由文本搜索:

https://api.chucknorris.io/jokes/search?query={query}

这是github仓库:

这些是产生错误的文件:

请:如果您只是想说我是在问错,请不要回答!我已经提供了我认为需要的所有信息。

编辑:花了我一段时间,但我意识到这是一个拼写错误?

1 个答案:

答案 0 :(得分:0)

在此处检查:https://codesandbox.io/s/github/analubarreto/chuck_jokes-hooks/blob/master/?file=/src/app/App.js 一切正常,我得到了API响应。请参阅屏幕截图。

让我知道您的期望是否与此不同。

enter image description here