Unable to load the data from the fake API - javascript

I am unable to load data from the fake API and I keep getting errors.
I have tried it on code sandbox.
https://codesandbox.io/s/charming-zhukovsky-lbq4n7?file=/src/Users.js
https://fakestoreapi.com/users
This is the fake API ,I am trying to get the data from. Looks like it has nested key -value pairs.
Please help me loop through this format of data.
Thanks!

The API seems to work as I get results. What I see is:
Uncaught Error: Objects are not valid as a React child (found: object with keys {firstname, lastname}). If you meant to render a collection of children, use an array instead.
So name is an object that contains firstname and lastname.
Try using {user.name.firstname} instead in the DOM render.

Related

Rest Api In Nodejs Express & MySql

Hey friends, so what happened is I developed a rest API using Nodejs Express and Mysql, It is working fine on my local machine, I then hosted it on Cpanel, now I am trying to fetch data from it and render it on my react app. Well fetching the data part works like magic, its even rendering in my console, but when I map the data on my react app it is giving the error below, and just a blank white page. May you please assist .
If the data object is still in a nested object (aka JSON) format, then using .map() on it won't work, as .map() is not a function for Objects.
Try converting data to an array of objects then use .map().
You can grab all the values with Object.values and push into an array that you can map

Firestore (javascript sdk) - Get only new data (not just adding)

Im using Firestore with web javascript sdk.
Assume following scheme:
User Doc -> Friends collection
I want to know when someone change/remove/add data to it.
so what I wrote is something like this:
friendsCollectionRef.onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
onChange(change);
});
});
The problem is that whenever I refresh the page, it keeps calling the onChange with data that was updated in my last session..
Is there a way to get only NEW data and not retroactively?
I would like to avoid store "LastUpdate" field on everything.
This, of course, should not be done in client side because then I pay for network which im never going to use..
So storing a boolean isFirstCall in out of the question.
As explained in the doc, when you listen to multiple documents in a collection with the onSnapshot() method:
The first query snapshot contains added events for all existing
documents that match the query. This is because you're getting a set
of changes that bring your query snapshot current with the initial
state of the query.
So each time you refresh your page you are calling again the onSnapshot() method "from scratch" and therefore you get the first query snapshot with all the collection docs.
In other words, I think you will have to implement your "home-made" mechanism to only get the documents you want (probably a "LastUpdate" field...).
You may be interested by this SO answer which shows how to add a createdAt timestamp to a Firestore document via a Cloud Function. You could easily adapt it to record the last update. It would be more complicated if you want to detect the Documents that were deleted since the last fetch.

Inconsistency between Android and JavaScript Parse API

I'm using Parse Server as a back end (the open source version). I have an Android application that saves an object to the server's DB. The object is simply a key-value pair. When the Android application creates an object, it creates it as JSON object.
Now I want to retrieve the same object from an Ionic 2 app. In Ionic, I use the JS Parse API to access the back end. When an object is created in the JS API, it's created as a plain text object.
As a result I'm getting: 101 Object not found
It seems like what I need to do is to translate Parse plain text object to Parse JSON object.
This is what I tried to do:
According to the JS Parse documentation one of the methods of Parse.Object is toJSON(). I tried to apply this method in different combinations to the Parse object before creating query, but I always get an error: this.parse.Object.extend(...).toJSON is not a function
I tried to apply standard JSON Api (i.e. JSON.stringify) to the Parse object. In this case I'm getting an error: ParseQuery must be constructed with a ParseObject or class name.
I did very extensive search on internet and found nothing helpful.
Would appreciate any ideas on the matter.
Figured it out. The problem was corrupted disk on the server side. Created new server and new DB and everything works fine now.

pass facebook response to flash callback external interface

I've try to pass response of facebook api request that I get it via FB JS-SDK into my flash application using external interface but I don't get what response type, it result [object object] when I print it in console but when I try type such as response.name or .id or using scope (some value display correct but some still display [object object]).
So,
First, what data type that returned by fb's response?
How I can pass it into flash apps, what about the type argument that I must set?
Then, which is the effective solution between extract the response each key that store it in an array then pass it into flash then extract again each part or send response object to flash then extract it in flash side?
I'm so confused because when I use JSON.decode method in js, it results nothing (undefined).
I'll appreciate for your attention and solution.
You shouldn't use JSON.decode your facebook data, you already get a JSON object that is ready to work with. Though flash doesn't know what is to be there in your JSON object so there will be no code snippets (consider it as a dynamic object)
For example, when you get your simple information about user*FB.api('/me'...)*, you have a .name property:
...
public function receivedResponce(response:Object):void
{
trace(responce.name);
}
...
You can get any other type of data returned by facebook request, whether it's a friend list or link to the user photo.
There's a lot of information about what fields do facebook requests return, try reading it's API guide

Backbone collection.get() not working

I'm trying to filter through a collection of lists in my router to show a particular list in a new view.
My collection of lists has already been fetched and is saved at MyApp.collections.lists, but when I try to do the following, it returns undefined. (id is a variable that I'm passing in from the router)
var list = MyApp.collections.lists.get(id)
What I don't get is that when I try the exact same code in the browser console, it returns the correct model no problem. I know it's not an issue with .fetch() timing because I log the collection object before and after I try to get the model and it shows up fine. I also know I also tried .getByCid() just to make sure that it wasn't a problem with the id itself and got the same results.
Any ideas what might be causing this?

Categories

Resources