#Nanostores
1 messages · Page 1 of 1 (latest)
Based on the provided code, it seems like you're trying to subscribe to a store from Nano Stores and set the view variable to the value from the store. However, it's important to note that according to the Astro documentation (https://docs.astro.build/en/recipes/sharing-state-islands/#why-nano-stores), you cannot pass a Nano Store as a “prop” to client-side components. Also, writing to a store from a .astro file or non-hydrated component will not affect the value received by client-side components.
Here's a snippet from the documentation:
FAQ
🙋 Can I use Nano Stores in.astrofiles or other server-side components? Nano Stores can be used in<script>tags to share state between.astrocomponents. However, Using Nano Stores in the frontmatter of server-side components is not recommended because of the following restrictions:
- Writing to a store from a
.astrofile or non-hydrated component will not affect the value received by client-side components.- You cannot pass a Nano Store as a “prop” to client-side components.
- You cannot subscribe to store changes from a
.astrofile, since Astro components do not re-render.
Given these restrictions, you might need to reconsider your approach to sharing state between components. You might want to explore alternatives such as Svelte’s built-in stores, Solid signals, Vue’s reactivity API, or sending custom browser events between components, as suggested in the Astro documentation.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@supple terrace kapa.ai is still learning and improving, please let us know how it did by reacting below
@lilac ingot como puedo hacer para poner query params a la url de mi sitio
Let me check the knowledge base for you. One moment! :books:
Para agregar parámetros de consulta a la URL de tu sitio en Astro, puedes hacerlo directamente en el código donde generas o rediriges a la URL. Aquí hay un ejemplo de cómo puedes hacerlo utilizando JavaScript:
let url = new URL('<https://tusitio.com/ruta'>);
url.searchParams.append('parametro', 'valor');
console.log(url.toString()); // <https://tusitio.com/ruta?parametro=valor>
Además, si estás trabajando con la API de Strapi y necesitas agregar parámetros de consulta a la URL, puedes hacerlo utilizando la función fetchApi proporcionada en la documentación de Astro (https://docs.astro.build/en/guides/cms/strapi/#creating-the-api-wrapper). Aquí hay un ejemplo de cómo puedes hacerlo:
import fetchApi from './src/lib/strapi.ts';
const data = await fetchApi({
endpoint: 'tusitio.com/ruta',
query: {
parametro: 'valor',
},
});