Giter VIP home page Giter VIP logo

react-app-tutorial's Introduction

๐Ÿ™Œ Special thanks go to easylearn schweiz ag. This is the company I currently work for. Our managers allowed me to create parts of this tutorial at working time.

react-app-tutorial

The purpose of this tutorial is to serve for a better understanding of the concepts of React while getting familiar with some state-of-the-art libraries used with it in 2022.

To go through this tutorial without lots of pain, you should be familiar with Javascript ES6+, React and JSX. This tutorial is written in Typescript. I think most people who understand Javascript can arrange with TS by doing this tutorial. No need to panic: It is just javascript with type hints.

Approach

Together we are going to build a single page app with an index and a register user page. The user registration form is going to be wired with a mocked api over http to also cover network traffic. The output of this tutorial is a clean and reusable framework built on top of React.

Out of scope

We do not cover redux in this tutorial. In my opinion and especially in this time (with React 16+) I think redux is an overkill for most cases. The trade-off between redux's code-splitting and therefore its higher complexity overwhelms the benefits of performance optimizations. I experienced that encapsulated components with its callbacks are a lot easier to understand and less error prone than reducers, actions and components which are split into different parts in the code base. For global and non steadily changed state I would suggest using the React's useContext hook.

Tutorial steps

Below you can see an overview of all steps of this tutorial.

  1. Setup from scratch - Installation: create-react-app, linting
  2. Authentication - Authentication context for the current user, import paths
  3. Routing - Preparing page layouts and the page's skeletons, mui, styled-components
  4. Internationalization - Translating contents, localization base, switching between two languages
  5. Toaster - Providing a way to trigger messages (toasts) to the website user
  6. Form - Providing basic form elements and the possibility of error enrichment
  7. Collections - Designing an interface for collection providers, implementation for arrays
  8. ApiV1 - Standardized http request handling, provide the first API version 1 endpoint
  9. Wiring - Wiring the registration form with the mocked http endpoint, form element error messages

๐Ÿ’ก To compare the code changes between the tutorial steps, just go to https://github.com/inkognitro/react-app-tutorial-code/compare and choose the specific tutorial step branches to compare. Some steps are split into smaller branches. Every step is an accumulation of all the steps before plus the code changes of the tutorial step.

Feel free to use the code for your own project. It's available under the MIT license ๐Ÿ˜‰

Let's start ยป

react-app-tutorial's People

Contributors

inkognitro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-app-tutorial's Issues

Webpack Deprecation Warnings

In config/webpackDevServer.config.js replace

    onBeforeSetupMiddleware(devServer) {
      // Keep `evalSourceMapMiddleware`
      // middlewares before `redirectServedPath` otherwise will not have any effect
      // This lets us fetch source contents from webpack for the error overlay
      devServer.app.use(evalSourceMapMiddleware(devServer));

      if (fs.existsSync(paths.proxySetup)) {
        // This registers user provided middleware for proxy reasons
        require(paths.proxySetup)(devServer.app);
      }
    },
    onAfterSetupMiddleware(devServer) {
      // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
      devServer.app.use(redirectServedPath(paths.publicUrlOrPath));

      // This service worker file is effectively a 'no-op' that will reset any
      // previous service worker registered for the same host:port combination.
      // We do this in development to avoid hitting the production cache if
      // it used the same host and port.
      // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
      devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
    },

with

    setupMiddlewares: (middlewares, devServer) => {
      // Keep `evalSourceMapMiddleware`
      // middlewares before `redirectServedPath` otherwise will not have any effect
      // This lets us fetch source contents from webpack for the error overlay
      middlewares.unshift(evalSourceMapMiddleware(devServer));
      if (fs.existsSync(paths.proxySetup)) {
        // This registers user provided middleware for proxy reasons
        require(paths.proxySetup)(devServer.app);
      }
      middlewares.push(
        // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
        redirectServedPath(paths.publicUrlOrPath),
        // This service worker file is effectively a 'no-op' that will reset any
        // previous service worker registered for the same host:port combination.
        // We do this in development to avoid hitting the production cache if
        // it used the same host and port.
        // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
        noopServiceWorkerMiddleware(paths.publicUrlOrPath)
      );
      return middlewares;
    },

Check node version in setup

Checking node version in setup is recommended, otherwise you may run into problems when using Jest. Anything under node version 16 is "old"

Fix vulnerabilities

Upgrade @svgr/webpack to ^6.2.1 in package.json to fix all vulnerabilities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.