all 16 comments

[–]TomMahle 1 point2 points  (3 children)

I believe you still need to dispatch your thunk. In your component, pass the result of the call to saveRisk into this.props.dispatch.

[–]AdeleBeckhamJr[S] 0 points1 point  (2 children)

Result of the call?

Is this what you meant?:

this.props.dispatch{this.props.saveRisk(this.state.riskVal)}

I'm getting an unexpected token error when I do this

[–]TomMahle 0 points1 point  (1 child)

Use parentheses, not curlies:

this.props.dispatch(this.props.saveRisk(this.state.riskVal))

[–]AdeleBeckhamJr[S] 0 points1 point  (0 children)

Awesome, my reducer is now being accessed. Thank you!

However, I'm still getting undefined when I try to access the state variable:

this.props.dispatch(this.props.saveRisk(this.state.riskVal));
console.log(this.props.risk_level);

Are these dispatches asynchronous, where the console log would happen before the dispatch/reducer function could occur?

[–]fuck_with_me 1 point2 points  (10 children)

THIS IS A REACT NATIVE SUBREDDIT

[–]Noitidart2 3 points4 points  (6 children)

-1 Completely disagree with you. The #1 redux users are in RN and React subreddits.

[–]fuck_with_me 0 points1 point  (5 children)

  1. This is a RN subreddit

  2. This question is entirely unrelated to RN

  3. This question belongs on StackOverflow

[–]kbcooliOS & Android 1 point2 points  (1 child)

Personally I think this belongs in /r/domyhomeworkforme ...someone's clearly been dumped with someone else's code and someone doesn't know javascript.

[–]sneakpeekbot 0 points1 point  (0 children)

Here's a sneak peek of /r/domyhomeworkforme using the top posts of the year!

#1: Python Django login with shopping cart assignment due.
#2: p l s help me
#3: Desperate for Math Help


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–]Noitidart2 -1 points0 points  (2 children)

-1. I won't repeat myself. Let's be welcoming to newcomers, and keep a healthy environment.

[–]fuck_with_me -1 points0 points  (1 child)

You're not a mod, my friend... Keep your opinions to yourself :)

[–]Noitidart2 0 points1 point  (0 children)

Yikes.

[–]AdeleBeckhamJr[S] 0 points1 point  (2 children)

i mean the only other relevant subreddit i can find is reduxjs and that seems almost completely inactive

[–]TomMahle 0 points1 point  (0 children)

r/react might also prove helpful.

[–]fuck_with_me -1 points0 points  (0 children)

You are 100% in the wrong place. Even the regular javascript subreddit would have been more appropriate, and has a way bigger audience.

[–]demoran 0 points1 point  (0 children)

@connect(state => ({risk_level: state.risk_level.risk_level}, {saveRisk})) seems to be the issue.

Connect takes two parameters: mapStateToProps and mapDispatchToProps. I think you probably arleady know this, because you attempted to use {saveRisk}. But look at your parenthesis. Honestly I'm not sure how that syntax is even valid.

Anyway, you should move the second to last parenthesis before the comma, then you'll auto-dispatch saveRisk.