【发布时间】:2021-06-27 15:38:09
【问题描述】:
const noticeList = useSelector(state => state.noticeReducer.list) //현재 페이지에 띄워질 공지 리스트
//page
const [current, setCurrent] = useState(0); //현재 페이지
const pageInfo = useSelector(state => state.noticeReducer.pageInfo); //전체 페이지 정보
const [keyword, setkeyword] = useState(null); //키워드 state
const [searchedList, setsearchedList] = useState(noticeList); // 검색 할때만 사용하므로 여기에 사용
const [active, setactive] = useState("");
console.log(searchedList)
const Search = () => {
const data = axios.post('/noticeList',{
keyword : keyword,
})
.then(res => res.data)
.catch(err => console.log(err));
setsearchedList(data)
}
useEffect(() => {
return (
dispatch(getNoticeList(current+1,keyword)) //공지사항 목록 받아오기
)
}, [dispatch, current])
//화면에 출력하기 위해 map 함수를 활용
let homeNotice = searchedList.map(
item =>
{
return(
<NoticeDetail key = {item.noticeId} title = {item.title} active = {active} setactive = {setactive} content = {item.content}/>
)
}
)
我在 Redux 中以 useEffect 的状态保存了数据。 我想在搜索功能中搜索时覆盖相同状态的数据。我该怎么办?
Uncaught TypeError: searchedList.map is not a function
【问题讨论】:
-
你的“noticeReducer”中“list”的initialState是什么类型?
标签: reactjs api rest react-redux