0

I've got an action that looks like this

export const setTokenTimeout = date => ({
type: SET_TOKEN_TIMEOUT,
date 

And I want to dispatch it inside of some middleware using Redux Logic, which looks like this

const requestLogin =
createLogic({
type: LOGIN_REQUEST,
latest: true,

process({ axios, push, action, getState }, dispatch, done ) {
  const { code, user } = action.payload
  const config = configure(progress(LOGIN_REQUEST)(dispatch))
  return axios.post(Api.AUTH_LOGIN, { code, user }, config)
  .then(res => {
    dispatch(handleSuccess(LOGIN_SUCCESS)(res))
    dispatch(push(Route.WELCOME))
    dispatch(setTokenTimeout())
    done()
  }).catch( e => {
    window.alert(e)
    dispatch(handleFailure(LOGIN_FAILURE)(e))
    dispatch(reset('LoginForm'))
    done()
  })

}

I want to pass in a date to my action like this

const date = new Date()
dispatch(setTokenTimeout(date))

But when I try to dispatch my setTokenTimeout function it catches an error that says

TypeError: (0 , _token2.default) is not a function

How can it not be a function?

If I just do

dispatch(setTokenTimeout) 

it doesn't give me an error, but I need to be able to pass a value into it.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
Christopher Mellor
  • 470
  • 2
  • 9
  • 23

1 Answers1

1

Yeah, you have a mismatch between your "named export" and a "default import". They need to be the same kind.

So, if you have export const setTokenTimeout, which is a named export, you need to have import {setTokenTimeout} from "./actions/token", which is a named import.

markerikson
  • 63,178
  • 10
  • 141
  • 157