Skip to content

自定义容器组件与element-react的table组件,context冲突 #965

@andyyxw

Description

@andyyxw

引入react-redux后,将组件分离为改为presentational和container两种组件,但是在渲染组件时出现了下面的警告:

Warning: Failed context type: The context `store.subscribe` is marked as required in `Connect(Update)`, but its value is `undefined`.
    in Connect(Update) (created by TableBody)

经过一番折腾,发现是自定义的container组件Update的context中的store,被它的父组件element-react的Table的context中的store顶掉了。
自定义容器组件:直接在App标签中渲染updater组件,context的store为Redux的store.
image
第三方库方式:updater组件包含在element-react的Table组件中,context的store却是TableStore.
image
严重警告代码出处:./presentational/content.js

import React, { Component } from 'react';
import { Table } from 'element-react';
import { connect } from 'react-redux';
import Update from '../containers/update';

class Content extends Component {
    constructor(props,context) {
        super(props);
        this.state = {
            columns: [
                {
                    label: '用户名',
                    prop: 'name'
                },
                {
                    label: '操作',
                    prop: 'zip',
                    fixed: 'right',
                    width: 240,
                    render: (row, column, index)=>{
                      return (
                            <div>
                                <Update/>
                            </div>
                        );
                    }
                }
            ],
            data: [{
                date: '2016-05-02',
                name: '王小虎',
                province: '上海',
                city: '普陀区',
                address: '上海市普陀区金沙江路 1518 弄',
                zip: 200333
              }]
        };
    }
    render () {
        return (
            <div className="Content">        
                <Table
                    style={{width: '100%'}}
                    columns={this.state.columns}
                    data={this.state.data}
                >
                </Table>
                <Update />
            </div>
        );
    }
}
export default Content;

请问该怎么解决?不胜感激

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions