小编Vit*_*sov的帖子

在redux中没有使用reactjs定义调度

我想知道为什么点击表格行仍然会给我未定义的调度错误导致Uncaught TypeError: dispatch is not a function.我一直在关注这篇文章,试图解决问题,但到目前为止还没有成功.

ListingTable.js

import Table from 'grommet/components/Table';
import React from 'react';
import {remove, add} from '../action/ListAction';
import {connect} from 'react-redux'

let createHandlers = function(dispatch) {
    let onClick = function(item) {
        dispatch(add(item)) <<== undefined!!!!
    };
    return {
        onClick
    };
};
export class ListingTable extends React.Component {

    constructor(props) {
        super(props);
        this.handlers = createHandlers(this.props.dispatch);
    }
    render() {
        return <Table>
                <tbody>
                {
                    this.props.data.map((item, key)=>
                        (
                            // Undefined Error!!!!
                            <tr onClick={()=> this.handlers.onClick(item)} key={key}>

                                <td>{item.user_name}</td>
                                <td>{item.name}</td>
                                <td>{item.url}</td> …
Run Code Online (Sandbox Code Playgroud)

javascript flux ecmascript-6 reactjs redux

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

标签 统计

ecmascript-6 ×1

flux ×1

javascript ×1

reactjs ×1

redux ×1