Skip to content

Conversation

@MattIPv4
Copy link
Member

This PR

Allows for setContext returned by the useContextMutator hook to be passed a method that returns the new context, with the current (previous) context passed into it. This aligns the signature of setContext to the setter of a regular useState hook, making it easier to conditionally update the context without needing to keep track of the domain separately from the React context.

@MattIPv4 MattIPv4 requested review from a team as code owners November 26, 2025 00:55
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MattIPv4, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the useContextMutator hook by allowing its setContext function to accept a callback. This callback receives the current context, enabling more flexible and reactive updates to the OpenFeature context, aligning its behavior with standard React state management patterns and improving the overall developer experience for context manipulation.

Highlights

  • Enhanced setContext signature: The setContext function returned by useContextMutator now accepts a method (function) as an argument, in addition to directly accepting the new context object.
  • Callback for context updates: When a function is passed to setContext, it receives the current (previous) context as an argument, allowing for conditional or derived context updates, similar to React's useState setter.
  • Improved developer experience: This change simplifies managing context updates, especially when the new context depends on the previous state, by removing the need to manually track the context outside the hook.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the useContextMutator hook by allowing setContext to accept a function, similar to React's useState setter. This provides a more flexible way to update the context based on its previous state. The implementation is sound and is accompanied by relevant test cases. I've found one potential issue regarding a missing dependency in a useCallback hook which could lead to stale closures.

@MattIPv4 MattIPv4 force-pushed the feat/set-context-hook-method branch from 00e3973 to 80c6528 Compare November 26, 2025 01:00
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
Signed-off-by: MattIPv4 <me@mattcowley.co.uk>
@MattIPv4 MattIPv4 force-pushed the feat/set-context-hook-method branch from 80c6528 to 9de51c7 Compare November 26, 2025 01:00
Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea!

Copy link
Member

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever! Could you please extend the JS Doc to mention this?

@beeme1mr beeme1mr added this pull request to the merge queue Nov 26, 2025
Merged via the queue into open-feature:main with commit 279f9bf Nov 26, 2025
10 checks passed
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

Successfully merging this pull request may close these issues.

3 participants