Hi all! Has anyone gotten this to work with React...
# community-help
k
Hi all! Has anyone gotten this to work with React Native? I’m building an app with Expo, using React Native code, and when I’m just trying to instantiate Typesense and assign a variable to the Typesense.Client, i get the error:
"TypeError: Cannot read property 'Client' of undefined".
I just try to get the client like in Step #2 of the Firebase docs
j
It should technically work with React Native, but I haven’t tried it myself. In this case, did you already import or require the Typesense library?
k
Yes, definitely did that
j
Hmmm, could you share the full code snippet you’re using?
Oh also, have you added it to package json, npm install, etc?
k
Above my screen component, it basically looks like this for now, just to try to see some results:
Copy code
import React, { useEffect, useLayoutEffect, useState } from 'react';
import { HeaderBackButton, StackScreenProps } from '@react-navigation/stack';
import Typesense from 'typesense';

type ScreenProps = StackScreenProps<AppStackParamList, 'Explore'>;



let searchClient = new Typesense.Client({
    nodes: [
        {
            host: '<http://pl8s6ubvg1afhmnwp-1.a1.typesense.net|pl8s6ubvg1afhmnwp-1.a1.typesense.net>', 
            port: '443',
            protocol: 'https'
        }
    ],
    apiKey: 'my-api-key',
    connectionTimeoutSeconds: 2
});

export default function ExploreScreen({ navigation, route }: ScreenProps) {
...
}
If you can’t see anything wrong with that, maybe i have to make a minimal reproducible app
and yeah, typesense is installed with:
Copy code
typesense": "^0.14.0,
j
Yeah I can’t see anything immediately wrong with it, but then I’m also not too familiar with React Native. If you can give me a minimal app to reproduce this in, I can take a closer look
k
yeah, it doesn’t seem much like a React Native error though but something else more rudimentary to js, but i’m not really sure. I did install
@babel/runtime
too. Thanks for the quick replies in any case!
On a side note, i was a little confused by the docs there, since, about the Firebase Extension (which I’m using) at the top of the doc, it states:
Copy code
If you choose to use this extension, you can skip directly to Step 4 below, once you set up the extension.
and then at Step 4, the code shows to use client variable, but not showing how to get the client.
🙏 1
so I’m assuming it’s the same as in Step 2.
j
Ah yes it is. Good catch, will fix that
👍 1