I was listening to Broken Walls at the Alaska State Fair. Jonathan Maracle, a Mohawk Indian, shared how they teach to be like the eagle. In a storm, every other animal goes and hunkers down to wait…
To illustrate, I’ll breakdown how I use a GET request to pull data into my Daily Journal App in React from my local json server.
Let’s break this down. In useState I set my initial state to an empty array. Then I name my state variable postData and my updater function setPostData. Now my component is stateful and can pass data to the setPostData updater function to store it in the postData variable.
I found that if I tried to call my GET request without using the Effect Hook, the GET request would be called twice, presumably once after the component rendered and then again when the control flow reached the GET request. This would create a bug publishing a duplicate of all data to the page.
Now that I have a successful response from the server, it’s time to render the data to the page. Because I stored the data in the State variable postData, I can traverse across the data array by calling the .map() method on postData.
Please feel free to leave comments, thoughts and recommendations below. Thanks!
Indian kitchen is full of tastes and flavors. It has its own spices to make every dish delicious but there are some adapted tastes like that tomato ketchup sauce. Every Indian kitchen is incomplete…
A leader is someone who guides other people into achieving something. There are good leaders and bad leaders. It takes conscious effort to be the former. As Christians and Kingdom leaders…
Welcome to the Party by BlackLight (aka Carl Davis) takes you back to a time of body-popping and breakdancing to 1980s house music. If you were around in those days, or even if you weren’t, this is a…