我无法从Redux商店获取状态值

时间:2018-08-02 11:46:17

标签: reactjs redux react-redux

我正在尝试使用react和redux渲染我的商店,但是它不起作用,这是我的App.js和我的store.dispatch在这里,我已经分派了两个费用

import React, { Component } from 'react';
import Header from './Header'
import Router from './reactRouter'
import configS from './stores/configS'
import {addExpense} from './actions/expenseA'
import {setTextFilter, } from './actions/filters'
import  filterV from './selectors/expense'

class App extends Component {


  render() {
    const store = configS()
    store.dispatch(addExpense({
      des: 'water bill',
      amount: 1000,
      createdAt: -21000,
    }))
    store.dispatch(addExpense({
      des: 'light bill',
      amount: 1000,
      createdAt: -21000,
    }))
    store.dispatch(setTextFilter('light'))
    // store.dispatch(startDate('20000'))

    const state = store.getState();
    const vFilters = filterV(state.expenses, state.filters);
    console.log(vFilters);


    return ( 
      <div className = "App" >
      <Header />
      <Router />
      </div>
    );
  }
}

export default App;

这是呈现我的商店的组件,它表示数组费用array.lenght为0。ExpenseList.js

import React from 'react';
import {connect} from 'react-redux';
import ExpenseListItem from './expenseListItem '



const ExpenseList= (props) => (
    <div className="App">
        <h1>Expense List</h1>
        {props.expenses.length}
        {props.expenses.map((expense) => <ExpenseListItem key={expense.id} {...expense} />)}
    </div>
);

const state = (state)=>({
    expenses:state.expenses,
    filters:state.filters
})

 export default connect(state)(ExpenseList)

1 个答案:

答案 0 :(得分:0)

自动换行(对于ExpenseList,为[top]父级)-如果页眉不需要访问存储,则为

return ( 
  <div className = "App" >
    <Header />
    <Provider store={store}>
      <Router />
    </Provider>
  </div>
);