Share state between Astro components
Это содержимое пока не доступно на вашем языке.
Using framework components? See how to share state between Islands!
When building an Astro website, you may need to share state across components. Astro recommends the use of Nano Stores for shared client storage.
Recipe
Section titled Recipe-
Install Nano Stores:
-
Create a store. In this example, the store tracks whether a dialog is open or not:
-
Import and use the store in a
<script>
tag in the components that will share state.The following
Button
andDialog
components each use the sharedisOpen
state to control whether a particular<div>
is hidden or displayed: