Astro pages with react components #362
subinpauljoy
started this conversation in
General
Replies: 1 comment
-
|
Sorry, this question is more about Astro. The only thing I can recommend—don’t do login in React’s |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Pretty new here. I am building a storefront experience using astro pages and react(jsx) components for cart, user interaction etc. I got to know about nanostores/query from the astro docs and somehow implemented a fetcher and mutator to manage auth and cart with my headless back end. I notice that each time when I change route, for example from /login to /cart my hydrator component fetches the back end and stores the result in the stores.
is it possible to optimize this? like the query/mutation result updates a store and it is available across astro pages(I believe it is a fresh load when we switch routes in astro) can experts take a look and help? project structure is as follows.
astro pages are there for /login, /cart, /checkout, /register, etc.
all astro pages are wrapped in a astro component which uses a Header react component as client:only.
the below component is the hydrator which is intended to hydrate cart and auth when the first time the site is loaded
From thereon, usual storefront activities like add to cart, remove from cart, login, etc happens. each of these happens in an astro page with a react component inside that. using nanostores/query to fetch from back end. upon successful result, the store is supposed to get updated. it happens when I am in the same page. Observed that the hydrator getting called each time I switch pages. is It possible to persist these stores in between pages and use it as dependency for use effect(or something similar) to optimize network calls?
Beta Was this translation helpful? Give feedback.
All reactions