Tutorials on React

Learn about React from fellow newline community members!

  • React
  • Angular
  • Vue
  • Svelte
  • NextJS
  • Redux
  • Apollo
  • Storybook
  • D3
  • Testing Library
  • JavaScript
  • TypeScript
  • Node.js
  • Deno
  • Rust
  • Python
  • GraphQL
  • React
  • Angular
  • Vue
  • Svelte
  • NextJS
  • Redux
  • Apollo
  • Storybook
  • D3
  • Testing Library
  • JavaScript
  • TypeScript
  • Node.js
  • Deno
  • Rust
  • Python
  • GraphQL

What is JSX?

Chances are you, if you've ever looked at a React component, you've seen JavaScript that looks like this: What is that stuff that looks like HTML or XML? That's called JSX and it stands for JavaScript eXtension. It might seem weird to have XML tags in your JavaScript, but it turns out to be super useful. By the end of this blog post, you'll have a solid understanding of what JSX is, and how we'll use it to build powerful React apps. All of our React components have a render function that specifies what the HTML output of our React component will be. JSX is a "language extension" that allows us to write JavaScript that looks like HTML.

Thumbnail Image of Tutorial What is JSX?

I got a job offer, thanks in a big part to your teaching. They sent a test as part of the interview process, and this was a huge help to implement my own Node server.

This has been a really good investment!

Advance your career with newline Pro.

Only $30 per month for unlimited access to over 60+ books, guides and courses!

Learn More

Props and state of React

Let's talk a bit about props and state , two core concepts in React that we'll use in every React application. The short of it is, props are like the "arguments" (or properties ) that you pass into your components and state stores "component-local data". Let's look at an example to make it concrete: Let's say that we have a <Header /> component that includes a title. The code might look something like this:

How to Use useReducer with TypeScript

The useReducer hook is a hook that allows you to create a state, update it, and share its data across different components. (Its core logic is similar to Redux .) It takes a reducer-function and an initial state as arguments and returns a tuple of a new state and a dispatch function. The reducer must extend the Reducer<State, Action> type, which is a function that takes a state and an action as arguments, updates the state, and returns the updated state:

How to Use React Refs with TypeScript

Refs provide a way to access DOM nodes or React elements created in the render method. Also, they can be used to store some references to entities or objects for accessing them later. To use refs with functional components use a special useRef hook . It is a generic function, so we can pass a type-parameter, that will tell TypeScript what type is acceptable for this ref.

How to Use State in React Components with TypeScript

When you need to store some data that won't be shared across components you can use the local component state. To use state in functional component use useState hook. This hook returns a tuple of two values. The first one is the current value of the state, the second one is a function to update the state. You can also increase type-safety declaring what types a state accepts:

TypeScript and React - how to prevent bugs by typing props, state, and hooks

TypeScript is fantastic to use with React because it can help us catch a lot of bugs we wouldn't catch otherwise. It helps our team have good documentation and it makes React easier to use (over the long term). But there were a lot of things I didn't understand in the beginning that I wish someone would have explained to me. In this post, I'm going to walk you through the basics of using TypeScript and React, with code.

Thumbnail Image of Tutorial TypeScript and React - how to prevent bugs by typing props, state, and hooks

A Guide to React createContext with TypeScript

In this post, we will dive into a technique for sharing data between React components using Context . While we usually use props to pass values, that doesn't always work if we have components in different parts of our component tree. We can use Context to share these values anywhere in our app (and we can use TypeScript to type them). Below, I'm going to show you:

Thumbnail Image of Tutorial A Guide to React createContext with TypeScript

Thinking in React Tutorial: a custom hook to capture keystrokes in TypeScript

Thinking in React can feel weird if you're not used to it. In this post, I'm going to show you a React-way to think about and use the native browser's APIs and hook them into your React app. Specifically, I'm going to show you how to listen for keystrokes in a React-y way. Keyboard shortcuts are making a comeback in webapps -- but this pattern is more than listening for keystrokes: it's a way of thinking: the React Way. Here's what we're going to build:

Thumbnail Image of Tutorial Thinking in React Tutorial: a custom hook to capture keystrokes in TypeScript

How to Handle Mouse Events in React TypeScript Application

When dealing with user interactions, you often need to handle some user events like mouse clicks, keyboard input, etc. To handle mouse event in React you can use MouseEvent type to declare types on handler event argument: You can specify the element on which an event is being handled. It improves the type-safety and shrinks possible properties and methods to those that apply to a given element.

How to Create a React Form: Controlled vs. Uncontrolled Components

In this article, we'll cover two ways to create React forms: the HTML way, with uncontrolled components, and the best practice, with controlled components.We'll discuss concepts such as: what are controlled and uncontrolled components, main tags used in a React form, and form validation and submission.

Thumbnail Image of Tutorial How to Create a React Form: Controlled vs. Uncontrolled Components

How to Install Types for Packages

When you develop an app you often use some third-party packages as dependencies. Not all of them are written in TypeScript, but many provide type declarations for a developer to be able to include those in a project. The biggest repository with type declarations is DefinitelyTyped . It contains type declarations for packages like React, Redux, Mobx, and many others. Some packages already have .d.ts files in them. These files contain type declarations. If your dependency package has it, you won't need to install types manually.

Thumbnail Image of Tutorial How to Install Types for Packages

Deploying Next.js Application on Vercel, Heroku, and a Custom Static Server

In this post, we will be looking at Next.js app deployment on different types of servers and using different technologies, such as: We will go through deployment setup on each technology step by step and show the code. Some time ago web-developers shipped their applications in production by hand. They might use FTP or some other protocols to copy built application assets to production server. This approach has a lot of downsides.

Thumbnail Image of Tutorial Deploying Next.js Application on Vercel, Heroku, and a Custom Static Server