So I think the direction you gave me is just another way of dispatching actions and I confirmed it still does the same thing. It calls my action but my reducer still won’t recognize this action.
They are not the same things
connect
is an HOC, this means it takes a function and return a new function with something “enhanced”. In this case takes a class/function and return that with some extra data and the dispatch method as props.
What you have created is a curry function.
To give you an explanation:
Imagine that our dispatch
is the following log
function:
const log = (...arg) => console.log('dispatched ', ...arg);
Nothing fancy, but you can paste it in the console and test it out.
This is how you declared your “dispatch” factory function: a function that takes an argument, and return a function.
// remember log is our dispatch
const f = input => {
console.log('action ', input);
return (log) => {
log(input)
}
}
so if you invoke:
f(1)
// action 1
// return [function]
and as you see there’s nothing that called our log function since f is returning a function.
In order to make it work you need to pass the desired function to the returned value of f
on in practice:
const myCustomEvent = f(1) // you'll see 'action 1' in console
myCustomEvent(log) // now we pass our missing piece, the second function
// dispatched 1
[yay! that worked finally]
However the advantage of using a function that pass log
(or dispatch) as argument to connect is that you don’t need to declare the firs portion of the function yourself since the HOC is taking care of that.
Or in code:
// we are passing log as first argument
const fakeConnect = (log) => ({
myCustomAction: x => log(x)
})
// then you connect a component
const connectedComponent = fakeConnect(log);
// in fact you have the Redux method as props
// that's why you can this.props.myCustomAction
connectedComponent.myCustomAction("I'M ALIVE") // "dispatched I'M ALIVE"
This is a working model so you’re free to test it out in a REPL
…phew, that took a while.
Also personal side-note / suggestion: don’t assume you’re right and everyone else is wrong
we’re here trying to help and not trying to make your life miserable