Sitemap
courtney

courtney

React Building Blocks 🚜

3 min readMay 19, 2022

--

React JS logo

After spending the past few months working exclusively with Vanilla JS, it was time for the next phase of my learning, React. This tool, would allow access to, “A JavaScript library for building user interfaces” per the official documentations. This tool strengthens a developer’s ability to create more organized, accessible, and concise code. Not only is React JS one of the best tools in the toolbox, it’s also a highly desirable skill as a web developer, if you didn’t already have reason enough to learn.

During my learning experience with React, there were three key fundamental concepts that I hope to summarize below. Enjoy 😊

React: Components 🗂

Once React is installed and you have your blank canvas ready to be utilized. One of the first steps in prepping your code for functionality is by creating components. Components are recyclable bits of code that work independently as referenced by, w3schools. Components can be equally compared to JavaScript functions. They help us organize our user interface’s login and presentation and enable us to think that each piece in isolation, and apply structure to complex programs.

In almost every single-page web application, the following component will be automatically generated after create-react-app:

Press enter or click to view image in full size

Within this component, React will process what is called JSX behind the scenes and the browser will then interpret that as JavaScript. See below:

Press enter or click to view image in full size
create react app home page
credit: w3schools.com

If there were a simple way to sum up components it would be this: A component is a function that takes props as an argument and returns JSX.

React: Props ☎️

Now that you have your applications components, props, allows developers to turn the React components into dynamic templates. React allows us to pass units of information from a parent component down to a child component. This is props! Let’s not forget to mention, props, can hold any kind of data: strings, numbers, booleans, objects, and functions.

Get courtney’s stories in your inbox

Join Medium for free to get updates from this writer.

The only way for a parent component to pass data to its child components is via props. Having the ability to share this data between components by passing props down to a child component from a parent makes our components incredibly flexible!

React: State 📓

Now that you have your components and props, it’s time to dive into State, and see how we can make our components respond to change dynamically. State is data that changes over time per user interactions on your application. There is a 3 question checklist that was provided to me during my initial learning of determining when to use state and when to not. The checklist looks like this:

  • 🚫 or ✅ Is it passed as a prop?
  • 🚫 or ✅ Can you compute it based on any other state or props in your component?
  • 🚫 or ✅ Does it remain unchanged over time?

By working with these building blocks of React for only two weeks, I was able to create multiple-single page web applications that consisted of a bank transaction ledger, Plant searcher, Pokemon Searcher and many more fun projects.

--

--