Hi Team
I need some help with user profile when a user register and logged in must show user profile on top and navigate to shopping cart in react-native some examples, will appreciate it and thanks a lot.
Hi Team
I need some help with user profile when a user register and logged in must show user profile on top and navigate to shopping cart in react-native some examples, will appreciate it and thanks a lot.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Brahma Prakash ShuklaPosted Apr 14, 2023, 7:11 AM
First, you'll need to create a registration and login system using a server-side technology such as Node.js with Express or Firebase Authentication. Once the user is authenticated, you can store their user data in a global state using a state management library like Redux or Context API.
To display the user profile on the top of the app, you can create a header component that shows the user's name or profile picture along with an icon to navigate to the shopping cart. This header component can be rendered on each screen of your app using a navigation library like React Navigation.
Here's an example of how the header component might look like:
In this example, the user data is retrieved from the Redux store using the
useSelectorhook. TheTouchableOpacitythe component is used to create a button that navigates to the shopping cart screen when pressed.Finally, you'll need to create the shopping cart screen, which can display the items the user has added to their cart and allow them to proceed with the checkout process. This screen can also be implemented using Redux or Context API to manage the state of the shopping cart.
I hope this helps you get started with implementing the user profile and shopping cart features in your React Native app!
Tuhin PaulPosted Apr 16, 2023, 6:37 AM
Here is the refactored code with TypeScript :
I added types to the Props and User objects, as well as to the useSelector hook. The Props object now has a "navigation" property of type "any" (although it would be better to specify a more specific type if possible). The User object has "photoUrl" and "name" properties, both of type "string". The useSelector hook now takes in a type parameter that specifies the shape of the Redux store, so that we can access the "user" property in the store with type safety.
Tuhin PaulPosted Apr 16, 2023, 6:27 AM
the
stylesobject has been replaced with aStyleSheet.createcall, which is a best practice for performance reasons in React Native. TheTouchableOpacitycomponent has also been moved above theViewcontaining the user profile information, which makes the cart icon appear on the left and the user profile information on the right.Guest UserPosted Apr 14, 2023, 3:45 PM
Hi Brahmna
Thanks for the clarification, i have firebase as a backend so now i know must only create a header to get the user profile, after user logs in be redirected to this component. I have Homescreen and LoginScreen, so must add this component as a third component in order to display user profile.