-
Notifications
You must be signed in to change notification settings - Fork 242
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
Fixes and improvements for some of Qwik examples #233
Conversation
One more thing. When you type event handlers in extracted function in Qwik there's better way to do it. Event handlers in Qwik take two arguments: an import { component$, useSignal, $, type EventHandler } from "@builder.io/qwik";
type PickColorHandler = EventHandler<Event, HTMLInputElement>
const PickPill = component$(() => {
const pickedColor = useSignal("red");
const handleChange = $<PickColorHandler>((_, {value}) => {
pickedColor.value = value;
});
return (
<>
<div>Picked: {pickedColor.value}</div>
<input
id="blue-pill"
checked={pickedColor.value === "blue"}
type="radio"
value="blue"
onChange$={handleChange}
/>
<label for="blue-pill">Blue pill</label>
<input
id="red-pill"
checked={pickedColor.value === "red"}
type="radio"
value="red"
onChange$={handleChange}
/>
<label for="red-pill">Red pill</label>
</>
);
});
export default PickPill; For some reason ESlint was complaining about unused variables in event handler (about the first argument) so I decided not to include this change. But now I don't see any error other than VSCode complaining that I need to enable |
Actually I found better way to improve radio button example for Qwik, thanks Vue 3 example for inspiration. The trick here is the props order, but it works same way, so no need for manual updates via event handler :) |
Qwik snippets are so much better, thanks a lot for your contribution ! You really understand the purpose of Component Party |
I've come across this website (this whole thing is a great idea btw) and while looking at the examples for Qwik I found some of them has issues that either cause errors, or they just overcomplicated. This PR fixes and improves upon these examples. Namely:
useTask$
callback when updated on initial render. In this example it will behave like an "on mount" lifecycle hook from other frameworks;useComputed$
function for when you need computed state, just like the other frameworks (I compared with Vue, React, Svelte and Qwik on the site);useComputed$
function because it's recommended way to derive computed values from application's state. Again, components are not closures, they are lazy-lodable chunks.bind:value
property;bind:checked
property;bind:value
property;useStore
withuseSignal
in every example I've changed, since reactive objects are not necessary in any of those, and also examples for other frameworks use appropriate APIs for state, unlike for Qwik examples.You can also play with these examples here: https://stackblitz.com/edit/qwik-starter-dxeodc