#How to handle clicking the checkbox and pass the value into the props?
39 messages ยท Page 1 of 1 (latest)
look like I need a store..
what happens when you add the checked attribute
<input type="checkbox" {checked}>
nothing changes
actual result vs expected
it could be a boolean, or text input with a string, doesn't matter
tried with nano store, but there is no reactivity ๐ค
it might help to understand that .astro uses a templating language
it allows you to load data for it asynchronously and renders non-reactive html
---
import { checked } from '../store.ts';
---
{checked.get()} // not ok, initial value
<label>
<input type="checkbox">
check
</label>
<script>
import { checked } from '../store.ts';
document.querySelector('input').addEventListener('input', (evt) => {
checked.set(~~evt.target.checked);
console.log(checked.get()); // ok here
});
</script>
hmm..
so how to add some dynamics? ๐
so the way you have it setup, the store update would happen on the server, but you are expecting the view to update on the client, the only way it could happen would be a full page refresh (astro renders the template again)
think form submissions
youd want to avoid that for something like a checkbox
id recommend letting a framework component do the reactivity
refresh the whole page, when you need update only 1 node, am I correct in understanding?
i should clarify, im not saying that's what should happen
just that when you expect reactivity from the server (the code within --- only runs on the server, and the template only renders on the server), refreshes the only way it can update the view on the client
yes, I roughly understand, thank you.
I mostly write in angular, Iโm used to completely different concepts ๐
so far it looks like astro is not quite suitable for the interactivity I have in mind
you would be right
it is not suitable for any reactivity
it just renders html, like php
oh I see, and for reactivity we should use frameworks integrations, rigth?
which is why we allow using react, vue, svelte, solid for interactivity
yes
there are third party integrations for angular and qwik too!
but the question arises: isnโt it easier for me to write everything in Angular? ๐
yes it is
I guess it depends on the project. if I understood the concept of islands correctly
introducing astro makes sense when performing an initial render of html gets your visitors a better experience
if interactivity is needed throughout the entire project, astro is not suitable, but if it is a static site with a separate widget, it may be good
exactly, for something like an interactive dashboard behind a login, the intial render doesnt matter at all, for example - going for a angular/react client-side only spa would be simpler
landing pages, docs, news and articles sites, on the other, benefit a lot from astro
thank you, it became much clearer. Iโll go think about what I want more from the current pet project ๐