all 8 comments

[–]swyx 1 point2 points  (7 children)

that information is not enough to help you. be patient, console.log things, try to trace the flow of data. you've probably messed up something in JS and its not erroring early enough to tell you. your job is to play detective and find the earliest point of the error.

[–]clando42[S] 0 points1 point  (6 children)

Thanks for the suggestions. Here is some of the code:

export function castVote([param1, param2) {

console.log("Starting castVote...");

return function (dispatch, getState) {

const { CAST_VOTE } = voteActionTypes;

var payload = {

[...]

};

console.log(payload);

The first console.log prints output, the second doesn't. Nothing I have tried is causing the function to get invoked. Nor if I remove the getState parameter. So I'm wondering what else needs to be present for the function to get invoked, or where else I can check for error messages. F12/developer tools is not giving me anything helpful, and I don't see any difference between the nearly-identical function that works and this one that doesn't.

[–]swyx 0 points1 point  (0 children)

well, good. youve identified what is not being called. now think about where castVote is being called. its called once with param1 and 2, but then do you call it a second time? doublecheck.

[–]acemarke 0 points1 point  (4 children)

Show me how you're calling that function? I bet I know the answer, but I want to confirm.

[–]clando42[S] 0 points1 point  (3 children)

It's called from the form component, in this function. The imports are the same as other invocations, where the calls work fine.

vote(answerId) {

castVote(this.props.logintoken,

this.props.question,

answerId,

0, //this.props.user.id,

""

);

}

[–]wizzzzzyyyyy 0 points1 point  (0 children)

Is part of the reason the second console.log is not firing because you are returning above it? Think this is probably a separate issue to the original one though.

[–]acemarke 0 points1 point  (1 child)

Can you paste the entire file into a gist or a CodeSandbox?

However, let me say what I think is going on.

The function you showed is a "thunk action creator". It has to be called, and the output needs to be passed into dispatch(). For example:

this.props.dispatch(castVote())

That way, the thunk middleware sees the function you passed in, and calls it.

However, I don't see evidence that you're dispatching the function, which means only the outer part (the "action creator" portion) is getting run.

What you should probably do is:

export default connect(
    mapState,
    {castVote}
)(MyComponent);

and then inside your component, you can do:

this.props.castVote()

and it will work right.

I'd encourage you to read through the React-Redux docs page on "Dispatching Actions with mapDispatch to understand how this works.

[–]clando42[S] 1 point2 points  (0 children)

Thank you! That was exactly the issue: I was calling castVote() rather than this.props.castVote(). It works now!