如何将数据从mapStateToProps传递到Next.js中的getStaticPaths

时间:2020-07-15 07:19:22

标签: reactjs redux react-redux next.js redux-thunk

我已经为动态页面循环了可能的ids列表,并且我正尝试将数据从Redux(ids列表)传递到getStaticPaths 。但是我无法从mapStateToProps中的getStaticPath中读取值。我在做什么错了?

import React from 'react';
import { connect } from 'react-redux';

import wrapper from '../redux/store';

import { util, manageList, reportList } from '../../components/helper';
import { getManageListAndCategoryId } from '../../redux/actions/actions';

export async function getStaticPaths(categoryIds) {
  console.log('categoryIds', categoryIds); // always undefined
  // temporarely make static path data while categoryIds is undefined
  const paths = [
    { params: { id: 'object' } },
    { params: { id: 'service' } },
    { params: { id: 'club_cards' } },
    { params: { id: 'schedule' } },
    { params: { id: 'agents' } },
    { params: { id: 'abonements' } },
    { params: { id: 'price_category' } },
    { params: { id: 'person_data' } },
    { params: { id: 'roles' } },
  ];
  return {
    paths,
    fallback: false,
  };
}

export async function getStaticProps({ params, manageProductsList }) {
  // const postData = util.findFormData(params.id, manageProductsList);
  const postData = { title: 'asdsadasdsad' };
  return {
    props: {
      postData,
    },
  };
}

const Form = ({ manageProductsList }) => (
  <div>
    dasdsadsad
  </div>
);

const mapStateToProps = (state) => ({
  categoryIds: state.mainReducer.categoryIds,
  manageProductsList: state.mainReducer.manageProductsList,
});

export default connect(mapStateToProps, null)(Form);

0 个答案:

没有答案