svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
920 stars 96 forks source link

setupedClient.client.request is not a function #62

Closed sho13 closed 7 years ago

sho13 commented 7 years ago

Hi,

I'm getting ^ that error from::

const axios = require('axios');

module.exports = {
  client: axios.create({
      baseURL: 'http://localhost:5000',
      responseType: 'json',
      // timeout: 5000,
    }),
}

and in my action it looks like this::

export const GET_SHIT = 'GET_SHIT';

export function getShit() {
return  {
    type: GET_SHIT,
    payload: {
      request: {
        method: "get",
        url: "/getShit"
      }
    }       
  }
}

but i get an error that says ::

Uncaught TypeError: setupedClient.client.request is not a function
    at eval (eval at <anonymous> (bundle.js:19090), <anonymous>:210:37)
    at Object.eval [as getValue] (eval at <anonymous> (bundle.js:19930), <anonymous>:4:12)
    at GettingShit.componentDidMount (eval at <anonymous> (bundle.js:7864), <anonymous>:91:18)
    at CallbackQueue.notifyAll (eval at <anonymous> (bundle.js:6336), <anonymous>:76:22)
    at ReactReconcileTransaction.close (eval at <anonymous> (bundle.js:17683), <anonymous>:80:26)
    at ReactReconcileTransaction.closeAll (eval at <anonymous> (bundle.js:1804), <anonymous>:206:25)
    at ReactReconcileTransaction.perform (eval at <anonymous> (bundle.js:1804), <anonymous>:153:16)
    at batchedMountComponentIntoNode (eval at <anonymous> (bundle.js:6432), <anonymous>:126:15)
    at ReactDefaultBatchingStrategyTransaction.perform (eval at <anonymous> (bundle.js:1804), <anonymous>:140:20)
    at Object.batchedUpdates (eval at <anonymous> (bundle.js:17575), <anonymous>:62:26)
(anonymous) @ bundle.js?4fc5:210
(anonymous) @ bindActionCreators.js?d387:3
componentDidMount @ gettingShit.jsx?4b86:55
notifyAll @ CallbackQueue.js?1e54:76
close @ ReactReconcileTransaction.js?e1cc:80
closeAll @ Transaction.js?b216:206
perform @ Transaction.js?b216:153
batchedMountComponentIntoNode @ ReactMount.js?ccff:126
perform @ Transaction.js?b216:140
batchedUpdates @ ReactDefaultBatchingStrategy.js?1670:62
batchedUpdates @ ReactUpdates.js?89d4:97
_renderNewRootComponent @ ReactMount.js?ccff:320
_renderSubtreeIntoContainer @ ReactMount.js?ccff:401
render @ ReactMount.js?ccff:422
(anonymous) @ index.jsx?f515:42
(anonymous) @ bundle.js:7085
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:21865
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:66
(anonymous) @ bundle.js:69

the index file with this stuff is::

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';

import axiosMiddleware from 'redux-axios-middleware';
import promise from 'redux-promise';
import createMemoryHistory from 'history/createMemoryHistory';
import client from './utils/axiosconfig.js';

import store from './reducers/index.js';

const history = createMemoryHistory();

const createStoreWithMiddleware = applyMiddleware(axiosMiddleware(client), promise)(createStore);

ReactDOM.render(
  <Provider store={createStoreWithMiddleware(store)}> 
etc.etc. 

is there something i'm doing wrong?

svrcekmichal commented 7 years ago

@sho13 can you send missing parts of how you setup redux with middleware?

sho13 commented 7 years ago

@svrcekmichal

const createStoreWithMiddleware = applyMiddleware(axiosMiddleware(client), promise)(createStore);

is this what you mean?

svrcekmichal commented 7 years ago

@sho13 yes, can you send whole file with imports etc?

sho13 commented 7 years ago

I apologize, NDA restricts me from doing so.

svrcekmichal commented 7 years ago

ok can you at least send how you import what's used in snippet above? at least axiosMiddleware, client

sho13 commented 7 years ago

Sure,

import axiosMiddleware from 'redux-axios-middleware';

client::


module.exports = {
  client: axios.create({
      baseURL: 'http://localhost:5000',
      responseType: 'json',
      timeout: 5000,
    }),
}
svrcekmichal commented 7 years ago

that's client export, not import

sho13 commented 7 years ago
import client from './utils/axiosconfig.js';
svrcekmichal commented 7 years ago

but you are not using default export in that export snippet, you are using named export client

can you try change import to import {client} from './utils/axiosconfig' another option is to change the export to default

sho13 commented 7 years ago

oh shit... you're right. thank you -_-

svrcekmichal commented 7 years ago

great :) don't worry, will close this issue