Site Logo

Mars RoverGram

Mars RoverGram Banner

Overview

During the 2023 Holiday season, I saw a post on LinkedIn that showed a list of free APIs that developers could use. Though I do not have access to the LinkedIn post, I did find a GitHub repository that lists many other free APIS (GitHub). Having worked on a project called “Astrogram”, I quickly became interested in the NASA API (NASA).

I chose the Mars Rovers API because I haven’t seen many of the images that the rovers have taken, so I became curious. I then got to work on a Minimal Viable Product (MVP) that featured the following things:

  • a Graphical User Interface (GUI)
  • Keyboard Navigation
  • Pagination and Shareable links
  • js v14 server actions
  • React 18 hooks
  • TailwindCSS

The API collects image data gathered by NASA’s Curiosity, Opportunity, and Spirit rovers on Mars. It is maintained by Chris Cerami (GitHub), and what I am exposing through this GUI are all the images, from multiple different cameras. For the MVP, I did not want to have a per camera filter, but it is something that can be added later. Some Cameras that all rovers have are the Front Hazard Avoidance Camera (FHAZ), the Rear Hazard Avoidance Camera (RHAZ), and the Navigation Camera (NAVCAM).

The final MVP checked all the boxes I had set! Read more about some of the challenges I encountered below!

Challenges and Solutions

Challenges

  • React 18 Canary Hooks
  • TailwindCSS
  • Next.js v14 Server Actions
  • Keyboard Navigation

React 18 Canary Hooks

I got the luxury of working with some of the latest and greatest hooks provided by React 18 like useFormStatus, useFormState, and useOptimistic. Since these hooks are stable and preleased under the Canary channel, Next.js v14 now supports them. While these hooks are stable, there are a few more things to keep in mind, especially as Next.js moves towards a separation of concerns between client components and server components.

These hooks provide some additional data when submitting forms to client components, like a pending state (Next.js Docs). With these values, we can then update the Front end as needed, while the server actions take care of what happens under the hood. Without these hooks, the GUI behaved like how GUIs behaved 15 years ago, where it did not have a loading state as it was fetching new images based on new parameters.

TailwindCSS

In the past, I have used pre-processors like SASS and I loved them. They allow flexibility and reusability of CSS code. I have also used component libraries like Chakra-UI and Material-UI (MUI). In recent years new tools have emerged, and one of them is TailwindCSS. I have heard mixed things about TailwindCSS, so I decided to use it on this project to form an opinion myself.

One of the things these all have in common is the time required to get these configured on your project or product, and having a solid foundation will prevent weird errors in the future. Once you have the project off the ground and configured, adding to the codebase becomes easier. Some things to keep in mind while configuring these tools are hydration, and client and server components. These will help you when you begin seeing inconsistencies or Flash Of Unstyled Content (FOUC).

I did some research and found that TailwindCSS can be lightweight, especially for smaller projects. It has a “prune” feature that removes styles that are not in use. I can see this become very useful should the application become complex. Reading the documentation motivated me to continue using it, as I also use utility classes. The naming of the Tailwind classes resembled some of the classes I used like flex, or mr-1.

After working with TailwindCSS, configuring it was the steepest curve, but once I began developing, TailwindCSS became very useful!

I can see using TailwindCSS in the future, and perhaps combining it with the MUI Base components (MUI Base Docs)!

Next.js v14 Server Actions

In v14, Next.js is separating client components and server components to achieve a separation of concerns. With this comes server actions, which are asynchronous functions that are executed in the server but can be used in client components and server components. These functions handle form submissions and data mutations.

In my opinion, server actions keep the file structure more organized. Tied with the React 18 hooks, and the UI can be rendered and updated much easier without the need to add third party dependencies.