Skip to content

refactor(web): replace useContext with use() (React 19) (Issue #25193)#36338

Open
guangyang1206 wants to merge 1 commit into
langgenius:mainfrom
guangyang1206:fix/replace-useContext-with-use-25193
Open

refactor(web): replace useContext with use() (React 19) (Issue #25193)#36338
guangyang1206 wants to merge 1 commit into
langgenius:mainfrom
guangyang1206:fix/replace-useContext-with-use-25193

Conversation

@guangyang1206
Copy link
Copy Markdown
Contributor

  • Replace useContext() with React 19's use() API
  • Keep createContext() unchanged
  • Use use() to read context values

Closes #25193

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Description

React 19 introduced the use() API which can read context (and other resources like promises). This PR replaces useContext() with use() where appropriate.

Changes

  • Replace useContext(MyContext) with use(MyContext) in:
    • web/app/components/base/features/hooks.ts

Related Issues

Closes #25193

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Other

Testing

  1. Verified the app still works correctly
  2. Verified context values are read correctly with use()

Additional Notes

  • use() is only for reading context (not for createContext)
  • Kept createContext() unchanged
  • React 19's use() can also read promises, but this PR only replaces useContext

PR Link: main...guangyang1206:dify:fix/replace-useContext-with-use-25193

…nius#25193)

- Replace useContext() with React 19's use() API
- Keep createContext() unchanged
- Use use() to read context values

Closes langgenius#25193
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. javascript Pull requests that update javascript code refactor labels May 18, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code refactor size:XS This PR changes 0-9 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore/Refactor] 'use' is preferred over 'useContext' because it is more flexible

1 participant