Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Expose LDProvider as a component in addition to the higher-order component. #174

Closed
threehams opened this issue Aug 24, 2019 · 2 comments

Comments

@threehams
Copy link

Is your feature request related to a problem? Please describe.
The provider is currently exposed as a higher-order component, with configuration supplied through an argument which can only accept a user available as a global. I'm currently in the process of setting up our layout component with hooks (react-cookies), and unfortunately, the user ID we need is only available from an API call. We're currently looking at adding this to the session cookie, but even then, it's going to involve imperative document.cookie calls - something we're avoiding in favor of universally SSR-safe cookies through context.

Describe the solution you'd like
Expose a new LDProvider component export, which is just these lines extracted to a new file, and this line moved inside the provider.

Describe alternatives you've considered
Imperatively access document.cookie instead of using useCookie() or any other client-only method for accessing cookies, with all checks for typeof window.

There doesn't appear to be any solution for dynamic user IDs outside cookies or other global storage.

Additional context
This was suggested in #166 previously, though that was in the context of switching users; this is about initialization without later changes. Allowing user to be a prop could lead to confusing behavior, as changing user will not really have any effect without further changes.

The HOC prevents the userId from changing after initialization, but with the negative effect of interop with other libraries.

Since ldClient is within scope of the provider code, it should be possible to listen to updates of user and call ldClient.identify whenever a change occurs.

I can make this change, if it's accepted.

@threehams threehams changed the title Request: Expose LDProvider as a component instead of a higher-order component. Request: Expose LDProvider as a component in addition to the higher-order component. Aug 24, 2019
@yusinto
Copy link
Contributor

yusinto commented Aug 28, 2019

Hi @threehams thanks for raising this issue. This is a good point and it's something we will officially support both in the base js sdk and in react sdk. The first step we'll take is to support a getter method to get the ld user from the base js sdk. We will then subsequently implement a user prop which will be available via the react sdk so consumers can subscribe to user changes.

We'll add this to our backlog so unfortunately I can not give an exact eta at this point in time.

@eli-darkly
Copy link
Contributor

Closing this because 1. I think it has already been addressed in the React SDK, and 2. if it hasn't, the place to discuss that is in the issues for https://github.com/launchdarkly/react-client-sdk, not js-client-sdk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants