我的組件不渲染,我沒有收到任何錯誤。我一直堅持這個錯誤幾個小時,所以我正在尋找任何建議!React/Redux組件不會渲染
我試圖獲得一個數據顯示,當頁面加載使用componentWillMount()並沒有任何顯示。在我能夠使用組件呈現簡單的字符串之前。現在我沒有從組件獲取任何控制檯日誌,沒有文本,沒有任何...我的api工作,但我沒有在Chrome控制檯中獲得http調用。以下是我的文件。
indexTimesheet.js(組分)
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import getTimesheet from '../actions/getTime';
class IndexTimesheet extends Component {
componentWillMount() {
console.log("test");
this.props.getTimesheet();
}
render() {
return (
<h3>Index Timesheet</h3>
);
}
}
IndexTimesheet.propTypes = {
getTimesheet: PropTypes.func
};
export default connect(null, {getTimesheet})(IndexTimesheet);
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware} from 'redux';
import {Router, Route, browserHistory} from 'react-router'; // , IndexRoute
import promise from 'redux-promise';
import reducers from './app/reducers';
const createStoreWithMiddleware = applyMiddleware(promise)(createStore);
// components
import {IndexTimesheet} from './app/components/indexTimesheet';
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<Router history={browserHistory}>
<Route path="/" component={IndexTimesheet}/>
</Router>
</Provider>,
document.getElementById('root')
);
getTime.js(動作文件)
import axios from 'axios';
export const GET_TIME = 'GET_TIME';
export const ROOT_URL = 'http://127.0.0.1:3055/api/v1/timesheet/';
export function getTimesheet() {
const request = axios.get(ROOT_URL);
return {
type: GET_TIME,
payload: request
};
}
時間表reducer.js
import {GET_TIME} from '../actions/getTime';
const INITIAL_STATE = {all: [], user: []};
export default function (state = INITIAL_STATE, action) {
switch (action.type) {
case GET_TIME:
return {state, all: action.payload.data};
default:
return state;
}
}
指數減速
import {combineReducers} from 'redux';
import TimesheetReducer from './timesheet';
const rootReducer = combineReducers({
time: TimesheetReducer
});
export default rootReducer;