title: Is it possible to pass a React Component the same function that created it?
body: <p>I'm trying to create a Pokedex web app. I have a Card component that displays an individual Pokemon, and within that I have navigation buttons to go back and forth down the list of Cards, and one to exit from the card. I have a function called createCard in the parent component that creates a card in the parent Component.</p>
  <pre><code>createCard = (key) =&gt; {
              
              const currentCard = (
              &lt;Card className=&quot;Card&quot;
              key={Pokemon[key].key}
              id={Pokemon[key].id}
              name={Pokemon[key].name}
              types={Pokemon[key].types}
              img={Pokemon[key].img}
              stats={Pokemon[key].stats}
              dexEntry={Pokemon[key].dexEntry}
              cry={Pokemon[key].cry}
              abilities={Pokemon[key].abilities}
              sprite={Pokemon[key].sprite}
              hideCard={this.hideCard}
              createTabs={this.createTabs}
              createCard={this.createCard}
              /&gt;
          )
  
          this.setState({
              currentScreen: currentCard
          })
      }
  </code></pre>
  <p>My issue is that the 'next' and 'previous' navigation buttons don't work (The exit one works fine). The way I set them up is that onclick, they should call the createCard function based on the Pokemon in my dictionary that's key value is one higher or lower than the current one.</p>
  <pre><code>&lt;div className=&quot;navButtons&quot;&gt;
                  &lt;button className=&quot;navBtn&quot; onClick={() =&gt; props.createCard(props.key - 1)}&gt;&amp;#10094;&lt;/button&gt;
                  &lt;button className=&quot;navBtn&quot; onClick={() =&gt; props.hideCard()}&gt;&amp;#10006;&lt;/button&gt;
                  &lt;button className=&quot;navBtn&quot; onClick={() =&gt; props.createCard(props.key + 1)}&gt;&amp;#10095;&lt;/button&gt;
              &lt;/div&gt;
  </code></pre>
  <p>When I push one of the navigation buttons though, I get &quot;TypeError: Cannot read property 'id' of undefined&quot; and it points to my createCard function. This is my first question on here, so I apologize if it's too lengthy, doesn't contain enough data, or something of the sort.</p>