0

I have the following code in my React Native app:

<View>
    <ToolBar
        ButtonRightText={"Submit"}
        onRightButtonPress = {(event) => {
            const form = this.cForm.wrappedInstance.wrappedInstance;
        }}
    />
    <ComponentForm 
        ref={(connectView) => {
            this.cForm = connectView
        }}
    />
</View>

This is a screen that contains <Toolbar> at the top, and <ComponentForm> below it. When the screen loads, the callback in <ComponentForm> is called, and connectView is an object like I expect. However, when I click the Submit button in <Toolbar>, it calls its callback which indicates that this.cForm is undefined.

So the problem is that this.cForm does get set when the screen loads, but then when I click Submit, this.cForm is undefined.

Anyone know how I can approach debugging this?

gkeenley
  • 6,088
  • 8
  • 54
  • 129
  • 1
    What is `this` actually? Is that piece of code inside of a class components render? – Jonas Wilms Feb 21 '20 at 14:57
  • 1
    Does this answer your question? [this.refs.something returns "undefined"](https://stackoverflow.com/questions/35230020/this-refs-something-returns-undefined) – Sterling Archer Feb 21 '20 at 14:57

0 Answers0