-
-
Notifications
You must be signed in to change notification settings - Fork 113
feat: add jsxBind
function to @preact/signals
#724
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for preact-signals-demo ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 4604dd9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
expect(scratch.innerHTML).to.equal("<div>Jane Doe</div>"); | ||
}); | ||
|
||
it("should update bound values without re-rendering the component", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test where we first return JSX and then text or something, similar to the normal SignalValue component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
This is missing a changeset btw |
Co-authored-by: Jovi De Croock <[email protected]>
Co-authored-by: Jovi De Croock <[email protected]>
Background
I briefly discussed this idea with @rschristian, who said I should try to implement it.
Link to discussion: https://preact.slack.com/archives/C3NMBSJKH/p1752172452437339
Goal
Avoid needing to declare "computed expressions" with
useComputed
, enabling you to write "inline computeds" where they're needed. This is intended for computeds that are only used by one JSX attribute or JSX child.How It Works
It's as easy as wrapping a "computed callback" with
jsxBind(…)
, a function exported by the@preact/signals
package.Key Features
useComputed
, the callback does not update on rerenderCurrent Limitations
Currently, there is no warning when trying to use
jsxBind
with a composite element, as this would require iterating the props object. Maybe someone has an idea about how to efficiently check for such misuse.Naming
Originally, I named it
bind()
, but decidedjsxBind()
makes its purpose a bit clearer. Ultimately, the name is up to you guys. :)