Trying to access information within localStorage - reactjs

I am trying to access information with-in localStorage from one component to another, specifically the name of the user on their profile. I am able to access up to the object holding all of the profile information like name, email, address etc. However when I try to extract just the name I am unsure of how to do so, or if its even possible.
right now im trying...
console.log(localStorage.document)
this gets me the an object holding all the data in localStorage...
{"name":"John Doe","email":"johndoe#aol.com","phone":"0000000000","address1":"123","address2":"123","addresscitystate":"Seattle, WA","addresszip":"00000"}
yet I cant seem to access any further then that. I attempted to just do [0] at the end to get the index but im getting just the letter back for that specific index not the actual object I want.
Any advise is appreciated!

May be you can try this one, For extracting the specific property from localStorage you can do this:
let item = localStorage.getItem("name")

The way to do this is.
First you need to extract the localStorage item
let savedItem = localStorage.getItem("username")
"Username" is the name of the item that is save in you localstorage.
The Complete guide for the localstorage usage is as follow.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Related

How do i use this fetched data response?

I Am using react. I have a fetch setup in an useEffect to grab the data from a database from the backend. It pulls the account and sends it back to the front where i can access it from there.
From the File I want to access the user information i have a console log
I want to be able to grab like the firstname, lastname individually and use them in the script. how do i go about that. I did try to console log UserData.user and it gave me this result
However when i went to try to get firstname like userData.user.firstname i was met with an error. Im pretty new to react and pushing myself with things ive never done before to learn and any help would be great
Thank you everyone who does help it means alot
Please note all information in screenshots are fictitious and are just prop data.
EDIT:
This may be because you are trying to read the user information before the api returns the data. so check if the array has data before trying to access it . You can use save navigation to check for undefined or null
UserData.user[0]?.firstname
Based on your screenshot the data you are getting back is an array of user objects. To access it you will need to use:
userData.user[0].firstname
Note that this will access the first user object in the array - you will likely need checks to ensure the data data exists before accessing it, e.g.:
if (userData.user.length > 0) {
// Access data as needed
}
user is an array so you can acces like this
userData.user[0].firstname;
it will be better if you update your endPoint to get an object instead, so you can have access and check easier

Pass data with react-location from one page to another page

Heyy,
Currently I am using react-location for routing and I am new with it.
I want to pass data from one page to another.
Is there any way to do it.I have read the documents but i am unable to find solution of my problem.
Thanks in advance.
I used navigation like this,
navigate({to: `/auth/reset-password`})
and with this i want to pass entered email field data.

Possibility to remove Parse.User.current() storing in localStorage

Is it possible to remove the object storing automatically in localStorage upon user logged in? Since this is in their documentation.
Parse.User.logOut() does this automatically but I suppose you are looking for a manuel way to do it.
Information of current user stores in localStorage as "Parse/APP_ID/currentUser"
APP_ID is the key you use when you initialize your Parse SDK
Parse.initialize("APP_ID", "JAVASCRIPT_KEY");
You can use removeItem() method in localStorage.
removeItem("Parse/APP_ID/currentUser")
If you want to do it with every login
Parse.User.logIn("myname", "mypass").then(user=>{
localStorage.removeItem("Parse/APP_ID/currentUser");
})

How to delete certain children of Firestore field array using Flutter

I am trying to make a Flutter and Firebase fitness application that saves runs a user logs. The runs are saved in an array called 'runs' in the Firestore database. Each document in my database represents a different user's runs, so the 'runs' array is a field found within each user's document. I have been trying to delete only a specific child of 'runs' but have had no luck. Does anyone know how to do this?
Here is my code for the delete function:
final CollectionReference runCollection = Firestore.instance.collection('runs')
Future deleteRun(dynamic runToDelete) async {
return await runCollection.document(uid).setData({
'runs': FieldValue.arrayRemove([runToDelete])
});
}
When I run this, I get no errors but nothing happens in the database.
I have also tried FieldValue.delete() but have not been able to isolate a specific index of 'runs' to delete without deleting the entire array.
Here is a picture of my firestore database:
Firestore.instance.collection(collection name).document(your document id).updateData({"array name": FieldValue.arrayRemove([delete object/array])}).than((value){print("delete");}).catchError((error){print(error);});
FieldValue.delete() only works when you know the entire contents of the array item to delete. It does not work with indexes, nor does it work with child values of array items.
What you will have to do instead is read the document, modify the array in memory, then write the modified array back to the document.

How to search for the form which is stored in local storage in angularjs?

I have a objects in which i am storing it into the local storage.If i want to store another object ,before it is saved i want to check wheather the object is already existed in the localstorage .If existed if u want to replace it or add it with another name .
I need to do this ..I am unable to identify how to search if number of objects are already stored in the local storage.Can anyone please solve this problem.
localStorage.setItem( $scope.form.Name, angular.toJson($scope.form));
you can't search in the local storage - you have to get the value from the storage and search it yourself, as you would with a file for example.
But you could use a [web database] (http://www.tutorialspoint.com/html5/html5_web_sql.htm) (also HTML5 feature) which allows you to store and find object in a DB.
use localStorage.get("prop") to verify if the name is already taken and the value exists (then you can compare values), if it's not you will get an undefined, so you can run this test
if (localStorage.get("prop")) {
// do something to prop because it exists
}
get length of localStorage by using the build-in length property, like
console.log(localStorage.length);
// will print 42 or something..
if you want to see what's inside localStorage, remember that it's an JS object like everything else so you can iterate it's properties using a for .. in loop
for (var prop in localStorage) {
console.log(localStorage[prop]);
}

Resources