Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (renderProps) {
- const components = renderProps.components;
- var componentObj = renderProps.components[2].WrappedComponent;
- const fetchData = (componentObj && componentObj.fetchDatas) || (() => Promise.resolve());
- const { location, params, history } = renderProps;
- const store = createStore(reducers, initialState, applyMiddleware(thunk));
- // calling this function which is place inside another component
- // I get error at below line stating cannot read property .then of undefined
- fetchData({ store, location, params, history })
- .then(() => {
- const markup= renderToString(
- <Provider store={store}>
- <RouterContext {...renderProps} />
- </Provider>
- )
- const state = store.getState();
- return res.render('index', { markup,initialState:
- JSON.stringify(store.getState()) });
- // if the current route matched we have renderProps
- }).catch((err)=> {
- console.log("error",err);
- })
- }
- class IndexPage extends React.Component {
- componentDidMount () {
- this.props.getCoffeeOrders();
- }
- // call the action creator
- static fetchDatas({store}) {
- store.dispatch(getCoffeeOrders);
- }
- render() {
- // render code goes here
- }
- import axios from 'axios';
- export const FETCH_COFFEE_ORDERS = 'FETCH_COFFEE_ORDERS';
- export function getCoffeeOrders() {
- //below line is getting printed on console
- console.log("getting coffee orders inside");
- return ((dispatch,getState) => {
- // below line is not getting printed
- // I think control does not come here
- console.log("mKe a call");
- return axios.get('http://localhost:8080/api/fetchcoffeeData').then((response)=> {
- console.log("got response", response);
- dispatch({
- type: FETCH_COFFEE_ORDERS,
- data
- });
- })
- .catch((err) => {
- console.log("got error while fetching data",err);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement