简体   繁体   English

我正在尝试在我的 react redux 应用程序中使用 map。 但使用useDispatch后,控制台显示错误

[英]I am trying to use map in my react redux app. but after using useDispatch, the console is showing error

I am working on an app, but I am getting errors in the console.我正在开发一个应用程序,但我在控制台中遇到错误。 I am sending the picture of the error, along with the code which causes the error.我正在发送错误图片以及导致错误的代码。 could anyone tell, me what causes this problem?谁能告诉我是什么导致了这个问题?

import React from 'react';
import { useSelector, shallowEqual } from 'react-redux';
import AddBook from './form';
import SingleBook from './singleBook';


const DisplayBooks = () => {
  const books = useSelector((state) => state.booksArray, shallowEqual);

  return (
    <div className="book-list">
      {books.map((book) => <SingleBook key={book.id} title={book.title} author={book.author} />)}
      <AddBook />
    </div>
  )
};

export default DisplayBooks;

Below I have pasted the console image.下面我粘贴了控制台图像。

image of the console控制台的图像

I think so this line of code is causing the problem我认为这行代码导致了问题

const books = useSelector((state) => state.booksArray, shallowEqual)

Change it to,改成,

const books = useSelector((state) => state.booksArray)
console.log(books) -> to check whether the books is an array or not

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法使用 react-redux (useDispatch) 使用基于 class 的组件进行反应? 我在渲染 function 中使用 useDispatch - Is there a way to use react-redux (useDispatch) in react using class based components? I am using useDispatch inside render function 我在将找到的现有 React 组件集成到我的应用程序中时遇到问题。 “尝试导入错误:” - I am having an issue with integrating an existing react component I found, into my app. "Attempted import error:" 尝试在我的应用中使用webpack。 获取“错误命令失败,退出代码为2”。 - Trying to use webpack in my react app. Getting a “error Command failed with exit code 2.” 我正在尝试在我的 React Native 应用程序中实现 Redux,因为教程使用 ReactDOM.render() 方法,但我似乎无法找到它, - I am trying to implement Redux to my React Native app, as tutorials use ReactDOM.render() method, and I cannot seem to locate it, 反应 Redux state 在调用 useDispatch() 后没有改变 - React Redux state not changing after calling useDispatch() react redux 为什么使用dispatch = useDispatch()? - react redux why use dispatch = useDispatch()? 当我试图启动我的反应应用程序时,我收到一个不寻常的错误。 它说CleanWebpackPlugin不是构造函数 - I'm getting an unusual error when I'm trying to start my react app. It says that CleanWebpackPlugin is not a constructor 我正在尝试使用 react-redux 存储我的数据,但它没有。 我该如何解决这个问题? - I am trying to store my data using react-redux, but it doesnt. How can I solve this? 我正在尝试从 mongodb 服务器呈现数据以响应应用程序。 它不工作 - I am trying to render data from mongodb server to react app. And it's not working 我在控制台中收到错误消息“您需要启用 JavaScript 才能运行此应用程序。” reactjs - I am getting error in console "You need to enable JavaScript to run this app." reactjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM