-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating state inside Static onRight() or onLeft() - undefined function error #2891
Comments
Since This was a limitation for us as well. We weren't able to come up with a reasonable solution for changing the state, but maybe someone else can chime in with ideas. |
Thanks. That makes total sense, I knew I was missing something/breaking some rules. Hopefully there's a work around. Anybody? |
Lets see if this makes sense.... Inside the onRight function you will need to get the ref for the component view. This can be found in the Actions.refs.SCENE_NAME (see #2256). so.. we bind the function to "this" in the constructor. `constructor(props) { We can then access it in the static
Remember if you are wrapping your class in connect (if you are using redux) you will need to add a withRef to the config settings of your connect call and use getWrappedInstance() to get the actual instance.
Of course the easiest way is just to use Actions.refresh in the componentDidMount though this is an anti-pattern
|
I was able to user Paul-Todd comment and (https://stackoverflow.com/questions/34004331/react-es6-how-to-access-child-component-functions-via-refs) to finally get my onRight method to call my component's method using redux without having to use static method on my class. I didn't have mapDispatchToProps but only mapStateToProps, so I used the following export line:
I called the submitStatusPost() method on NewStatusPage component from my scene using the following:
The getWrappedInstance method returned my current mapStateToProps values in my redux store for NewStatusPage. Also newStatus is the key to my scene using NewStatusPage as its component. |
Thanks @Paul-Todd you save my life |
hi @wardjk87 . where do you put your ref ? . I have try
it doesn't work |
@timeturnback If I'm understanding the solution correctly you don't create a ref yourself but rather use the one provided by the router. It should be |
Version
Tell us which versions you are using:
"react": "^16.2.0",
"react-native": "^0.51.0",
"react-native-beacons-manager": "^1.0.7",
"react-native-calendars": "^1.16.1",
"react-native-elements": "^0.18.5",
"react-native-router-flux": "^4.0.0-beta.27",
Expected behaviour
Update this.state.daySelected to today's value
Actual behaviour
Getting error of undefined function, either:
this.goToday.bind(this)
However, these functions work fine outside of the Static onRight() {}
What am I missing here?
What's the best way to update state when using Static onRight() or onLeft() ?
Thanks
The text was updated successfully, but these errors were encountered: