Coder Social home page Coder Social logo

Comments (3)

matthewelwell avatar matthewelwell commented on July 28, 2024

Hi @davinov thanks for this. I think that the link you included is pointing to a different line of code than the one you mentioned in the fix?

I'm not overly familiar with the JS client so I'm waiting for one of our other engineers to respond, but I'd be interested to know if there is a particular scenario you have identified where flagsmith is not set? I would imagine this to always be set. Perhaps it's a typing issue further down the line for example? Should useContext ever not return a valid instance of flagsmith?

from flagsmith-js-client.

davinov avatar davinov commented on July 28, 2024

Thanks for your quick reply

You're right about the line, my mistake!
The same condition is repeated twice in this file:

  • once in FlagsmithProvider L41: this seems OK because there the flagsmith argument is of type IFlagsmith, and not optional
  • once in useFlagsmithLoading L114, which gets flagsmith from the context useContext(FlagsmithContext). In that case, it seems that it could be null because of the intiialization value of the context (export const FlagsmithContext = createContext<IFlagsmith<string,string> | null>(null)

So another possibility would be to change the initialization value to a "default" flagsmith instance. However, that instance would not have any of important the parameters expected to be set by the consumers of the package, such as api or environmentID, so I guess this second option seems less appropriate to me.

I'll try to make a minimal reproduction repo this evening if I can spare some time.

from flagsmith-js-client.

davinov avatar davinov commented on July 28, 2024

When creating a new repo, I've noticed that my import of flagsmith/react was mistaked. My IDE imported automatically flagsmith/src/react instead 🤦
That included your source code to our typechecking, instead of relying on the exposed types (the .d.ts files).

You may still want to fix the error that raises when developing your client though, if you got some time :)
Screenshot from 2023-11-23 01-24-16

Thanks again for the quick reply, and sorry for the noise

from flagsmith-js-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.