Skip to content

docs: document useConstant - #8827

Merged
wmertens merged 2 commits into
QwikDev:v1from
youdie006:docs/useconstant
Jul 20, 2026
Merged

wmertens merged 2 commits into
QwikDev:v1from
youdie006:docs/useconstant

Conversation

@youdie006

Copy link
Copy Markdown

Closes #8237.

Documents useConstant, which previously existed only in the auto-generated API reference with no hand-written guide.

  • Adds a ## useConstant() section to the State docs page (core/state/index.mdx), mirroring the sibling useSignal / useStore / useComputed$ sections: an intro, a runnable CodeSandbox example, and a note distinguishing it from useSignal / useComputed$ (a value computed once and never re-run).
  • Adds the live demo the example points at (demo/state/use-constant/index.tsx), matching the sibling demos.

Content is grounded in the JSDoc from the issue and the source signature (useConstant in packages/qwik/src/core/use/use-signal.ts).

Note: the source still carries the @deprecated This is a technology preview tag on useConstant, so the generated API reference currently shows an "obsolete" warning. I documented it as a usable hook per the V2 intent described in this issue β€” happy to adjust if you'd prefer to reconcile the deprecation status separately.


AI disclosure: this PR was drafted with Claude Code (AI-assisted). The content is grounded in the issue's JSDoc and the source, and validated structurally.

Add a useConstant section to the State docs page mirroring the sibling hook
sections, plus the live demo it references. Grounded in the source signature
and the JSDoc from the issue.
@youdie006
youdie006 requested a review from a team as a code owner July 13, 2026 04:58
@changeset-bot

changeset-bot Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

πŸ¦‹ Changeset detected

Latest commit: eed589f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik Patch
@builder.io/qwik-city Patch
eslint-plugin-qwik Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a60eae6f6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

maiieul
maiieul previously approved these changes Jul 13, 2026

@maiieul maiieul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM πŸ‘ I think we can remove the flag for V2 indeed.

@wmertens wmertens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Small change please:

useConstant re-ran the factory for both null and undefined results. Guard on
!== undefined so a null result is retained; document that undefined results
re-run each render. Adds a unit test and documents useConstant.
@youdie006

Copy link
Copy Markdown
Author

Done, thanks for the review!

  • Changed the guard to val !== undefined, so a null result is now retained and only an undefined result re-runs the factory (with an explanatory comment + a JSDoc note).
  • Documented in the guide that a factory returning undefined is re-run each render; defined values (including null) are retained.
  • Added the note in the demo that componentId stays the same for the component's lifetime.
  • Added a changeset (@builder.io/qwik patch) and a use-signal.unit.tsx test proving the null-is-retained / undefined-re-runs behavior (red on the old guard, green on the new one), and ran api.update to sync the generated API docs.

Drafted-by: Claude Code (Opus 4.8) (no human review before posting)

@youdie006
youdie006 requested review from a team as code owners July 14, 2026 10:58
@wmertens
wmertens changed the base branch from main to v1 July 16, 2026 14:26
@youdie006

Copy link
Copy Markdown
Author

@wmertens gentle nudge on this one - I pushed the val !== undefined guard change (so null is retained and only undefined re-runs), the docs + demo updates, a changeset, and a use-signal.unit.tsx test a few days ago. Whenever you have a moment, happy to have another look. Thanks!


Drafted-by: Claude Code (Opus 4.8) (no human review before posting)

@wmertens wmertens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@wmertens
wmertens enabled auto-merge July 20, 2026 08:27
@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@builder.io/qwik@8827
npm i https://pkg.pr.new/@builder.io/qwik-city@8827
npm i https://pkg.pr.new/eslint-plugin-qwik@8827
npm i https://pkg.pr.new/create-qwik@8827

commit: eed589f

@wmertens
wmertens merged commit 841d645 into QwikDev:v1 Jul 20, 2026
39 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 23, 2026
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.

[πŸ“–] useConstant is not documented

3 participants