Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need help ! #78

Closed
lyquocphong opened this issue May 7, 2020 · 1 comment
Closed

I need help ! #78

lyquocphong opened this issue May 7, 2020 · 1 comment

Comments

@lyquocphong
Copy link

Hi !
I am newbie with this project and I have few question want to ask:

  1. What is the usage of the the api/session ? I know it can pass down the session data through the child but we can also do that with appData. Another thing is how I can update and get back session data for each user. Do I need use redis or any db to store the session and get session data back based on the id which I will set to user cookie ?

  2. What is the usage of useAppStore hook ? in pages/_app.js why don use appData direct from pageProps ? Why _app don use createLazyProps like another pages ?

  3. I want to make simple app like the shopping cart ? But I want to make the cart persistent, do I need to store using db when add to cart and in api/cart I will get the cart details out of db. ?

  4. What is the usage of appData ? I can see that for the Server side rendering, the appData handler will be call in fullfillRequestAPI but I wonder how I can set the appData when I am in one specific page which is render on client side.

  5. About the SessionContext, there is only one action is updateCartCount and it will update only in context, so how can I add more actions for session Context. Maybe I would like to have action to add product or logged user into session ?

@markbrocato
Copy link
Contributor

  1. What is the usage of the the api/session ? I know it can pass down the session data through the child but we can also do that with appData. Another thing is how I can update and get back session data for each user. Do I need use redis or any db to store the session and get session data back based on the id which I will set to user cookie ?

api/session is fetched when the app loads in the browser and is meant to establish a session with your ecommerce platform. How this is done depends on the platform. Generally you return any data associated with the user session. For example, the number of items in the cart.

What is the usage of useAppStore hook ? in pages/_app.js why don use appData direct from pageProps ? Why _app don use createLazyProps like another pages?

The idea is to only include app level data in the initial SSR response. For example, the data needed to build the main menu and navigational tabs. These generally don't change and thus including this data with every subsequent API response just slows things down and uses more network bandwidth. The useAppStore hook makes it easy to access this app level data from anywhere in your app at any point during the browsing flow.

  1. I want to make simple app like the shopping cart ? But I want to make the cart persistent, do I need to store using db when add to cart and in api/cart I will get the cart details out of db. ?

React Storefront is meant to be deployed on top of a headless ecommerce platform like Shopify or CommerceTools that provides the catalog, payment processing, and cart persistence for you. Those platforms typically store the user session in a database.

  1. What is the usage of appData ? I can see that for the Server side rendering, the appData handler will be call in fullfillRequestAPI but I wonder how I can set the appData when I am in one specific page which is render on client side.

App data is always provided during server side rendering and generally not updated thereafter. See my answer to 2.

  1. About the SessionContext, there is only one action is updateCartCount and it will update only in context, so how can I add more actions for session Context. Maybe I would like to have action to add product or logged user into session ?

You make a good point here - there should be a way to update session data in general. Let us think on this and figure out what changes should be made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants