My component is not rendering and I am not getting any errors. I have been stuck on this error for a few hours now so I am looking for any advice!
I am trying to get a data to display when page loads using componentWillMount() and nothing is currently showing up. Before I was able to render simple strings with the component. Now I am not getting any console logs from components, not text, nothing... my api works but I am not getting http calls in chrome console. Below are my files.
indexTimesheet.js (component)
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 (action file)
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
};
}
timesheet 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;
}
}
index reducer
import {combineReducers} from 'redux';
import TimesheetReducer from './timesheet';
const rootReducer = combineReducers({
time: TimesheetReducer
});
export default rootReducer;