title: TypeError: undefined is not an object (evaluating 'ejRepository.getWordandMean')
body: <p>I'm trying to retrieve data from a pre-populated database using TypeORM using Expo, imitating this working example (<a href="https://dev.to/jgabriel1/expo-sqlite-typeorm-4mn8" rel="nofollow noreferrer">https://dev.to/jgabriel1/expo-sqlite-typeorm-4mn8</a>). It keeps throwing this error;</p>
  <pre><code>undefined is not an object (evaluating 'ejRepository.getWordandMean')
  at src/components/page/dictionarypage.js:32:28 in useCallback$argument_0
  at src/components/page/dictionarypage.js:32:28 in useCallback$argument_0
  at [native code]:null in callFunctionReturnFlushedQueue
  </code></pre>
  <p><strong>UPDATE</strong></p>
  <p>After some investigation and edits, I've found  out <code>ejRepository</code> on dictionarypage.js is undefined, and <code>context</code> on connection.tsx is returning an empty object. I'm  wondering why.</p>
  <p>It seems like the connection is established already.</p>
  <p>Here's my updated code</p>
  <p>/page/dictionarypage.js</p>
  <pre><code>.
  .
  import { DatabaseConnectionProvider, useDatabaseConnection } from '../../data/connection';
  import { setinputWord } from '../../actions/action';
  import { connect } from 'react-redux';
  
  
  function DictionaryScreen(props){
      const { inputWord } = props;
  
      const { ejRepository } = useDatabaseConnection();
  
             // console.log indicates ejRepository is undefined
      
      const [wordData, setwordData] = useState(&quot;&quot;),
            [meanData, setmeanData] = useState(&quot;Word and definitions will appear here&quot;);
      
   
      const handleinputWord = async () =&gt; {
        try {   
              const results = await ejRepository.getWordandMean();
                                           
                                           //this is where the error is thrown
  
              setwordData(results.word);
              setmeanData(results.mean);
  
        } catch (error) {
            console.log(error)
        };
  
  
      return(
             &lt;DatabaseConnectionProvider&gt;
              &lt;SafeAreaView style={styles.container}&gt;
                  &lt;View style={styles.searchContainer}&gt;
                      &lt;MaterialCommunityIcons name=&quot;text-search&quot; color=&quot;white&quot; size={30}/&gt;
                      &lt;TextInput
                          style={styles.input}
                          onChangeText={mapDispatchToProps}
                          onSubmitEditing={handleinputWord}
                          value={inputWord}
                          key={inputWord}
                          placeholder='Look up the word (Type exactly)'
                          keyboardType=&quot;default&quot;
                      /&gt; 
                  &lt;StatusBar style='light' /&gt;
                  &lt;/View&gt;
                  
                  &lt;View style={{flex:40, margin:10, alignItems:&quot;center&quot;}}&gt;
                      &lt;Text style={{color:'white',fontSize:30,fontWeight:&quot;bold&quot;,margin:10}}&gt;
                          {wordData}
                      &lt;/Text&gt;
                      &lt;ScrollView&gt;
                          &lt;Text style={{color:'white',fontSize:18}}&gt;
                          {meanData}
                          &lt;/Text&gt;
                      &lt;/ScrollView&gt;
                  &lt;/View&gt;
                  &lt;View style={{margin:20, flex:1,alignItems:&quot;center&quot;}}&gt;
                      &lt;Text style={{color:&quot;white&quot;,fontSize:11}}&gt;
                          Data retrieved from ****
                      &lt;/Text&gt;
                  &lt;/View&gt;
              &lt;/SafeAreaView&gt;
            &lt;/DatabaseConnectionProvider&gt;
          );
      }
  
  const mapStateToProps = state =&gt; {
          return { 
              inputWord: state.inputWord
          }
      }
      
  const mapDispatchToProps = dispatch =&gt; {
          return {
              onChangeText: inputWord =&gt; dispatch(setinputWord({type: 'updateTextInput', inputWord}))
          }
      }
      
  export default connect(mapStateToProps, mapDispatchToProps) (DictionaryScreen);
  </code></pre>
  <p>/data/repositories/repository.ts</p>
  <pre><code>import { useSelector } from 'react-redux';
  import { Connection, Repository, Like } from 'typeorm';import { EJmodel } from '../entities/EJmodel';
  
  interface RootState{
      inputWord: string
  }
  
  export class EJRepository {
      private ormRepository: Repository&lt;EJmodel&gt;;
  
      constructor(connection: Connection) {
        this.ormRepository = connection.getRepository(EJmodel);
      }
  
      public async getWordandMean(): Promise&lt;EJmodel[]&gt; {
          const inputWord = useSelector((state: RootState) =&gt; state.inputWord);
      
          const results = await this.ormRepository.find({word: Like(inputWord)}
      );
      
        return results
      }
  }
  
  </code></pre>
  <p>/data/entities/EJmodel.ts</p>
  <pre><code>import {Entity, PrimaryColumn, Column} from &quot;typeorm&quot;;
  
  @Entity('ejdict.v1.0')
  export class EJmodel {
  
      @PrimaryColumn({type: 'integer'})
      item_id: number;
  
      @Column({type: 'text'})
      word: string;
  
      @Column({type: 'text'})
      mean: string;
  
      @Column({type: 'integer', select: false})
      level: number;
  
  }
  </code></pre>
  <p>/data/connection.tsx</p>
  <pre><code>import React, {createContext, useCallback, useContext, useEffect, useState} from 'react';
  import { ActivityIndicator } from 'react-native';
  import { Connection, createConnection } from 'typeorm';
    
  import { EJmodel } from './entities/EJmodel';
  import { ejdict1621603544180 } from './migration/1621603544180-ejdict';
  import { EJRepository } from './repositories/repository';
  
    
    interface DatabaseConnectionContextData {
      ejRepository: EJRepository;
    }
    
    const DatabaseConnectionContext = createContext&lt;DatabaseConnectionContextData&gt;(
      {} as DatabaseConnectionContextData,
    );
    
    export const DatabaseConnectionProvider: React.FC = ({ children }) =&gt; {
      const [connection, setConnection] = useState&lt;Connection | null&gt;(null);
    
      const connect = useCallback(async () =&gt; {
        const createdConnection = await createConnection({
          type: 'expo',
          name: &quot;ejdict.v1.0&quot;,
          database: 'ejdictcopy.db',
          driver: require('expo-sqlite'),
          entities: [EJmodel],
    
          migrations: [ejdict1621603544180],
          migrationsRun: true,
    
          synchronize: false,
          extra:{
            createFromLocation: '/Users/**/**/assets/db/ejdictcopy.db'
          }
        });
    
        setConnection(createdConnection);
      }, []);
    
      useEffect(() =&gt; {
        if (!connection) {
          connect();
        }
      }, [connect, connection]);
    
      if (!connection) {
        return &lt;ActivityIndicator /&gt;;
      }
    
      return (
        &lt;DatabaseConnectionContext.Provider
          value={{
            ejRepository: new EJRepository(connection),
          }}
        &gt;
          {children}
        &lt;/DatabaseConnectionContext.Provider&gt;
      );
    };
    
    export function useDatabaseConnection() {
      const context = useContext(DatabaseConnectionContext);
    
      return context;
    }
  </code></pre>
  <p>Other files and configurations are pretty much the same as the example shown above.</p>
  <p>At the beginning, I thought it was because the property <code>inputWord</code> was not properly read in the query as a parameter, so I installed react-redux and pass the property as a global variable. However, I feel like that's not the point.</p>
  <p>I'd appreciate any help or information about this problem.</p>