Console.Log输出混乱

时间:2020-05-27 22:56:51

标签: javascript reactjs

我目前正在尝试解决在将新道具添加到图形后呈现show.js的错误。目前,我记录了this.props.notes来查看未定义的内容,但我不了解所记录的1是什么。我不确定为什么在图和问题。

library(devtools)
source_url('https://gist.githubusercontent.com/fawda123/7471137/raw/466c1474d0a505ff044412703516c34f1a4684a5/nnet_plot_update.r')

plot.nnet(fit)
Console.Log
(2) [{…}, undefined]
0:
content: "test"
graph:
id: 3
info_url: "https://www.cdc.gov/mmwr/volumes/69/wr/mm6915e3.htm"
name: "Rates of Hospitalization for COVID-19"
screenshot_url: "https://www.cdc.gov/mmwr/volumes/69/wr/social-media/mm6915e3_HospitalizationsCOVID19_IMAGE_08April20_1200x675-medium.jpg"
__proto__: Object
id: 27
__proto__: Object
1: undefined
length: 2
__proto__: Array(0)


Show.js:27 Uncaught TypeError: Cannot read property 'graph' of undefined
    at Show.js:27
    at Array.filter (<anonymous>)
    at Show.render (Show.js:27)
    at finishClassComponent (react-dom.development.js:17160)
    at updateClassComponent (react-dom.development.js:17110)
    at beginWork (react-dom.development.js:18620)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at beginWork$1 (react-dom.development.js:23203)
    at performUnitOfWork (react-dom.development.js:22154)
    at workLoopSync (react-dom.development.js:22130)
    at performSyncWorkOnRoot (react-dom.development.js:21756)
    at react-dom.development.js:11089
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11084)
    at flushSyncCallbackQueue (react-dom.development.js:11072)
    at discreteUpdates$1 (react-dom.development.js:21893)
    at discreteUpdates (react-dom.development.js:806)
    at dispatchDiscreteEvent (react-dom.development.js:4168)

index.js:1 The above error occurred in the <Show> component:
    in Show (created by ConnectFunction)
    in ConnectFunction (created by Context.Consumer)
    in Route (at App.js:29)
    in div (at App.js:24)
    in div (created by Container)
    in Container (at App.js:23)
    in Router (created by BrowserRouter)
    in BrowserRouter (at App.js:22)
    in App (at src/index.js:23)
    in Provider (at src/index.js:22)

1 个答案:

答案 0 :(得分:0)

notes数组中的一个元素是undefined,因此,由于尝试从undefined对象访问图形键,您会感到兴奋。您可以检查是否在过滤条件中未定义图。

const notes = this.props.notes.filter(
  note => note.graph !== undefined && note.graph.id === graph.id
);

还要检查notes状态的来源并修复undefined注释状态。

相关问题