[英]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.下面我粘贴了控制台图像。
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.