Javascript 我不断地得到这个错误;TypeError:无法读取属性';一些';“未定义”的定义;

Javascript 我不断地得到这个错误;TypeError:无法读取属性';一些';“未定义”的定义;,javascript,reactjs,debugging,Javascript,Reactjs,Debugging,这里是我使用函数的地方: <span className={`icon-eye${ moviesWatched.some(watch => watch.id === movie.id) ? "-blocked" : "" }`} onClick={() => handleChange(movie)} /> 这就是MoviesWated获取it值的方式: handleChange= (movie) => { this.setState

这里是我使用函数的地方:

<span className={`icon-eye${
  moviesWatched.some(watch => watch.id === movie.id)
    ? "-blocked"
    : ""
  }`}
  onClick={() => handleChange(movie)}
/>
这就是MoviesWated获取it值的方式:

handleChange= (movie) => {
  this.setState({toggleWatched:!this.state.toggleWatched}, () => this.Toggling())

  const { moviesWatched } = this.state;
  const { id } = movie;
  const _movie ={id};

  if(!moviesWatched.find(watch => watch.id === movie.id)){
    return this.setState({moviesWatched:[...moviesWatched,_movie]})
  }

  const WatchedList = moviesWatched.filter(watch => watch.id !== _movie.id)
  this.setState({moviesWatched:WatchedList})
}
为什么会出现错误:

TypeError:无法读取未定义的属性“some”


即使是难看的
moviesweated
也不是
未定义的

moviesweated
未定义的
,因此尝试在其上使用
某些
会导致错误。你能提供更多的代码吗,这样我们就可以看到电影观看的来源了。太好了。你能展示一下你的整个组件吗?仍然很难确定到底是什么地方出了问题。渲染方法如何?我在这里看到了一些不一致之处。它是
moviewasted
还是
moviewasted
(noice the
s
)?您如何从状态访问
moviewasted
?约定位于渲染方法的顶部,用于分解道具和state
const{moviewswatched}=this.state
handleChange= (movie) => {
  this.setState({toggleWatched:!this.state.toggleWatched}, () => this.Toggling())

  const { moviesWatched } = this.state;
  const { id } = movie;
  const _movie ={id};

  if(!moviesWatched.find(watch => watch.id === movie.id)){
    return this.setState({moviesWatched:[...moviesWatched,_movie]})
  }

  const WatchedList = moviesWatched.filter(watch => watch.id !== _movie.id)
  this.setState({moviesWatched:WatchedList})
}