This will render a special UI for testing on top of the site itself.
The first thing that I like to do is to complete all tests that looks for HTML elements with certain tags. I started Five Server extension on VSCode, and started working.
This gives me an idea what is the final structure of the website.
After that, I included the necessary libraries: React, React DOM, and jQuery. Then I started dart-sass and babel with watch option.
It's time for React code!
The bare minimum
The next thing that I do was writing a div with id="wrapper". This will be the root of our React stuff. After an hour I have this:
"What?! You took an hour doing this?". Sadly, yes. I stumbled upon an error that complains about the usage of ReactDOM instead of 'ReactDOM/client'. It's a black hole of energy and time 😵💫.
It turns out that React is planning to separate its server-side rendering script with the client-side. This felt weird cause there is no CDN links for client-side one. Only a general ReactDOM CDN link. I don't know how to deal with this yet, but the code still works anyway 🧐.
I then proceeded to wrote the rest of components, and put them inside the parent component.
The FreeCodeCamp's test confirmed that I have a correct HTML structure. It's time for the logic!
Playing with APIs
As the project's name suggests, I need to show a random quote each time a user presses a button.
Because I'm not too wise to make hundreds of reliable quotes, I had to find APIs that serve them. A few Google searches later, I found what I need.
Quotable is a free, open source quotations API. It was originally built as part of a FreeCodeCamp project. If you are interested in contributing, please check out the Contributors Guide.
Servers
Name
URL
Description
Production
api.quotable.io
The public API server
Staging
staging.quotable.io
The staging server is for testing purposes only. The master branch automatically deploys to the staging server after every commit. Once changes have been tested they will be pushed to the production server.
FreeCodeCamp gave an example for each project. This is the example for this one:
I want to try and replicate what has been done here. So after two hours, I finally got a simple result!
Notice that I didn't randomize the colors yet.
Here's the code if you're curious:
This function is called each time the button is pressed. It also need a CSS variable --color, used as the color for text. Place the variable in the <HTML> tag.
Afterwords
Personally, this is a big jump in React stuff. Notice that I didn't use Redux. This is because the state is simple enough that I don't want to be burdened with more unnecessary library. I felt that I like my website light, rather than bloated with features.
Anyway, hope everyone else is doing good with their challenge 😁