反应: 类型错误: 调度不是一个函数

我想从重复中获取。我正在学习本教程:https://codesandbox.io/s/react-redux-application-hewdb?file=/src/pages/PostsPage.js


但是当我在代码中使用它时,那就是:


import React, { useState, useEffect } from 'react';

import { connect } from 'react-redux';

import {fetchInterview} from '../actions/interviewActions'


const DetailInterview = (props, { dispatch, loading, interviews, hasErrors }) => {


  console.log("test interview",interviews)

  useEffect(() => {

    const { match: { params: { id } } } = props;

    dispatch(fetchInterview(id))

  }, [dispatch])


  const interviewslist = interviews


  console.log('interview: ', interviews)


  return (

    <div>

      <h3>All participants</h3>

      <table>

        <thead>

          <tr>

            <th>ID</th>

            <th>Interview id</th>

            <th>Partcipants id</th>

            <th>Time</th>

          </tr>

        </thead>

        <tbody>

          {

            console.log('interviews:sad ', interviews)

          }

          {

            interviews? interviews.map((interview) => {

              console.log('sadassad',interview)

              console.log('sadaghahhgsghssad',interviews)

              return (

                <tr key={interview.id}>

                  <td>{interview.id}</td>

                  <td>{interview.interview_id}</td>

                  <td>

                    {/* <Link to={`/posts/${post.id}`}> */}

                    {interview.participant_id}

                    {/* </Link> */}

                  </td>

                  <td>{interview.created_at}</td>

                </tr>

              ) 

            }) : null

          }

        </tbody>

      </table>

    </div>

  );

}


// export default DetailInterview;


const mapStateToProps = state => ({

  loading: state.interview.loading,

  interviews: state.interview.interview,

  hasErrors: state.interview.hasErrors,

})

export default connect(mapStateToProps)(DetailInterview)

我收到一个错误: 未捕获的类型错误: 调度不是一个函数


无法理解这背后的错误是什么。


慕婉清6462132
浏览 103回答 1
1回答

慕田峪9158850

您正在从详细信息查看的第二个参数中解构值,而您应该从属性中执行此操作,因为 mapStateToProps 中的值和连接可用作所连接组件的 propsconst&nbsp;DetailInterview&nbsp;=&nbsp;(props)&nbsp;=>&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;{&nbsp;dispatch,&nbsp;loading,&nbsp;interviews,&nbsp;hasErrors&nbsp;}&nbsp;=&nbsp;props; &nbsp;&nbsp;&nbsp;&nbsp;... }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript