Comments (4)
I think that would benefit from some rewording, but they are not exactly contradicting.
Explaining:
Can I use Nano Stores in .astro files or other server-side components?
Nano Stores can be imported, written to, and read from in server-side components, but we donโt recommend it! This is due to a few restrictions:
- Writing to a store from a .astro file 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 .astro file, since Astro components do not re-render.
That is referring to server-side components, on Astro components that means the frontmatter:
---
// This runs on the server, not recommended
import {flag} from './stores.js';
const flagValue = flag.get();
---
A <script>
block in an Astro component is a plain client-side script generated by the Astro component, it is never executed on the server-side even when pre-rendering. Using nanostores there is not a problem.
---
---
<script>
// This runs on the client, perfectly fine
import {flag} from './stores.js';
const flagValue = flag.get();
</script>
from docs.
Good point! I should have clarified a bit more in my issue regarding the differences between using nanostores in frontmatter
and script
blocks and not have been in a rush.
from docs.
Thanks for the conversation here! I wonder if something like this would address the issue?
Existing:
Nano Stores can be imported, written to, and read from in server-side components, but we donโt recommend it! This is due to a few restrictions:
Change to something like...
Nano Stores can be used in
<script>
tags to share state between.astro
components. However, Using Nano Stores in the frontmatter of server-side components is not recommended because of the following restrictions:
Would something like that help? If so, would someone like to make a PR to update with clearer guidance?
from docs.
I think that is a great improvement!
from docs.
Related Issues (20)
- Zod compatibility HOT 3
- Document View Transition events fields HOT 7
- Abount Fontsource package name HOT 2
- View Transitions Script Behavior HOT 1
- Double/triple click headings copy issues HOT 2
- Getting errors creating a new project
- The remark config documentation misses some important information HOT 3
- Clarify how to implement social image URLs HOT 4
- Missing explanation about "themes" from ShikiConfig in syntax highlighting HOT 2
- โ ๏ธ Issue - The implementation of themes from Shiki is not working properly. HOT 1
- Add a bit more help text to client:only description
- Give us feedback form Appearance is not in line with Astro Doc Styling HOT 1
- RTL Docs `Inline Code Snippet` need to be always LTR.
- Deploying to GitHub Pages is problematic/flakey HOT 1
- Prettier plugin content is incorrect. HOT 1
- Middleware: unclear that reading cookies/headers behaviour
- Improve documentation on fallback content for slots HOT 2
- Unclear refactoring task
- Script Tag CDNs with View Transitions
- `prose-p:text-justify` makes recipe less usable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.