Something Code


Techincal blog posts about the lastest I've learned

React Key Attributes

Anytime you transform an array to a list of components in React, you need to add a key attribute to each item:


Why Redux Thunk

When I started learning how to use Redux, I was introduced to the Redux Thunk library. At that time I did not have a good grip on Redux, and learning another JS library was exactly what I did not need. After I wrote my first app using Redux, I felt the time was ripe to read up and write about why Redux Thunk is needed.


How To Handle No Returned Results From an API Query

For my final assessment, I created a flight reservation application. The user enters a form that has a date, destination city, and arival citiy field. When the form is submited, an api call to the backend server is triggered to query for flights. If the server returns found flights, the user will see a componet with a list of flights. If the query returns no results, the user should only see a message component saying “the query returned no results”. The first way I implemented the logic for this was to check the length of the returned flights list for the length of zero:


Accessing React Router's History Object

On my recent react project, I had a child component that unfortunately did not have react routers history props passed down into it. I was able to solve this by importing the withRouter function from the react-router-dom module, and exporting my own component with the withRouter function. This fuction takes an arguement of a componet and returns a higher-order component that has react routers props passed down into it (much like the beloved connect() function from Redux). Here is what the component would look like:


Rails Submit Button Disabling on Submit

By default, a rails form submit button will disable on submit. This is a great feature for preventing multiple of the same resources being created. But that is not always what is wanted. I was creating a form to create resources through a jquery ajax request and then have the response rendered without a page refresh. I wanted this to happen multiple times and disabling the submit button on submit was exactly what I did not want to happen. I addded the follwing line of code to my submit button: