小编meA*_*rew的帖子

使用网格系统响应 InfiniteScroll

发生什么事了,伙计们?我有一个对象数组,我有网格容器,我通过数组进行映射并渲染网格项目。一切都很好,除了所有网格卡同时渲染并且我有一个很长的列表。所以,我决定添加infiniteScroll组件。但所有卡片仍然同时渲染。这是我从组件中返回的内容:

<>
      {pokemonData ? (
        <>
          <InfiniteScroll
            dataLength={pokemonData.length}
            next={handleChangePage}
            hasMore={true}
            loader={<h4>Loading...</h4>}
            endMessage={
              <p style={{ textAlign: "center" }}>
                <b>Yay! You have seen it all</b>
              </p>
            }
          >
            <Grid container spacing={4} className={classes.pokemonCardsArea}>
              {pokemonData.map(
                (pokemon, index) =>
                  pokemon.name.includes(searchInputValue) && renderCards(index)
              )}
            </Grid>
          </InfiniteScroll>
        </>
      ) : (
        <CircularProgress
          color={"success"}
          className={classes.progress}
          size={200}
        />
      )}
</>
Run Code Online (Sandbox Code Playgroud)

handleChangePage 函数只是将页面状态设置为 page + 1;我没有任何错误,只是呈现了一个完整的列表,并在其底部加载...。我没有找到任何关于“下一个”功能到底应该是什么的信息。但有人做了 setPage 函数,所以我也做了同样的事情。一切都适合他(他渲染图片,连续一张),但不适合我,我想是因为网格系统。有人曾经成功地在 MUI 网格系统中实现过无限滚动吗?我没有主意,我无法入睡)有人帮忙)

grid infinite-scroll reactjs material-ui

3
推荐指数
1
解决办法
3160
查看次数

Redux工具包combineReducers问题:Store没有有效的reducer。确保传递给combineReducers的参数是一个对象,其

请告诉我我做错了什么?配置Store.js:

import {configureStore, combineReducers} from "@reduxjs/toolkit";
import pokemonSearchSlice from "./slices/pokemonSearch";

const reducer = combineReducers({
pokemonSearch: pokemonSearchSlice
});

const store = configureStore({
reducer
});



export default store;
Run Code Online (Sandbox Code Playgroud)

pokemonSearch.js

import { createSlice } from "@reduxjs/toolkit";



const pokemonSearchSlice = createSlice({
    name: "pokemonSearch",
    initialState: {
        searchInputValue: ""
    },
    reducers: {
setValue:(state, action)=>({...state, searchInputalue: action.payload})
    }
}) ;



export const {setValue} = pokemonSearchSlice.actions;

export default pokemonSearchSlice;
Run Code Online (Sandbox Code Playgroud)

错误全文:redux.js:394 Store 没有有效的减速器。确保传递给combineReducers 的参数是一个值为reducer 的对象。另外,我无法从商店获取“searchInputValue”,控制台显示:无法解构“(0,react_redux__WEBPACK_IMPORTED_MODULE_2__.useSelector)(...)”的属性“searchInputValue”,因为它未定义。但我认为这是因为combineReducers 错误。有什么建议么?

reactjs redux redux-toolkit

2
推荐指数
1
解决办法
9949
查看次数