Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a modern front-end application for you...

Building a modern front-end application for your project

React has evolved into one of the biggest players in the JS ecosystem. In this workshop, we will take a look at how to use both React and TypeScript and discuss some of the bigger pitfalls and challenges in bringing these two technologies together—and why I think they could be a great fit for your projects on the next phase of TechLabs.

We’ll wrap up our day going through a sample application, its codebase, and learning from it!

Matheus Albuquerque

December 13, 2020
Tweet

More Decks by Matheus Albuquerque

Other Decks in Programming

Transcript

  1. The goal here is not to introduce you to React,

    TypeScript or any of the mentioned technologies. edyoucated—and other online resources—are there for this. goals.html goals
  2. Help you not commit the same mistakes I did when

    writing my first React applications. goals.html goals
  3. Help you build applications that you won’t have to rewrite

    from scratch in case you want to maintain them after TechLabs. goals.html goals
  4. application_structure.html application structure Let's follow a regular create-react-app skeleton with

    very few modifications. Under the src folder, we have two main directories:
  5. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/
  6. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ Contains, as the name suggests, shared behavior, including…
  7. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ The main API client and also some data utilities (e.g. hooks for querying and mutating data)
  8. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ Images, CSS files, and other static assets
  9. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ Components reused across pages
  10. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ Main state management logic
  11. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ Reusable layouts
  12. application_structure.html application structure |-- shared/ | |-- api/ | |--

    assets/ | |-- components/ | |-- core/ | |-- layouts/ | |-- utils/ Helper functions reusable across the project
  13. application_structure.html application structure |-- modules/ | |-- auth/ | |--

    sign-in/ | | |-- ... | |-- sign-up/ | | |-- ... | |-- ...
  14. application_structure.html application structure |-- modules/ | |-- auth/ | |--

    sign-in/ | | |-- ... | |-- sign-up/ | | |-- ... | |-- ... These are each isolated functionality. Examples are:
  15. application_structure.html application structure |-- modules/ | |-- auth/ | |--

    sign-in/ | | |-- ... | |-- sign-up/ | | |-- ... | |-- ... Split into sign-in and sign-up
  16. application_structure.html application structure | |-- orders/ | |-- details/ |

    |-- components/ | |-- core/ | |-- hooks.ts | |-- models.ts | |-- index.ts Split into details and list
  17. application_structure.html application structure | |-- orders/ | |-- details/ |

    |-- components/ | |-- core/ | |-- hooks.ts | |-- models.ts | |-- index.ts Each module is organized in:
  18. application_structure.html application structure | |-- orders/ | |-- details/ |

    |-- components/ | |-- core/ | |-- hooks.ts | |-- models.ts | |-- index.ts Components relevant to that page
  19. application_structure.html application structure | |-- orders/ | |-- details/ |

    |-- components/ | |-- core/ | |-- hooks.ts | |-- models.ts | |-- index.ts The module state management logic
  20. application_structure.html application structure | |-- orders/ | |-- details/ |

    |-- components/ | |-- core/ | |-- hooks.ts | |-- models.ts | |-- index.ts Selectors, data access and mutation, and other hooks
  21. styling styling.html • UI Frameworks (e.g. Material UI) • CSS-in-JS

    (e.g. styled-components) • CSS preprocessors (e.g. SASS)
  22. routing tooling.html Routing is the process of keeping the browser

    URL in sync with what’s being rendered on the page.
  23. routing tooling.html React Router lets you handle routing declaratively. The

    declarative routing approach allows you to control the data flow in your application by saying “the route should look like this”.
  24. forms tooling.html Component-driven front-end libraries, like React, can ease the

    task of wiring web forms but can also get verbose and redundant.
  25. forms tooling.html Formik is a small library that solves the

    three most annoying parts of writing forms in React: • State manipulation • Form validation (and error messages) • Form submission
  26. forms tooling.html Also, it is our job to ensure that

    when users interact with the forms we set up, the data they send across is in the form we expect.
  27. forms tooling.html Yup is a JavaScript object schema validator. While

    it has many powerful features, we’ll focus on how it helps us create custom validation rules so we don’t have to.
  28. data fetching tooling.html SWR is a lightweight library that allows

    fetching, caching, or refetching data in realtime using React hooks.
  29. data fetching tooling.html It’s built with React Suspense, which lets

    your components “wait” for something before they can render, including data.
  30. • Free • Free Private Repo Hosting • Free SSL

    • Free DNS • deploying tooling.html
  31. • Easy to use • Deploy in seconds • Continuous

    Deployment (CD) • Branch Deploys • Deploy Previews • deploying tooling.html
  32. typescript • Advantages • Common concerns • Case Studies typescript.html

    • Typing your state • Typing your components • Typing your styles
  33. typescript • Advantages • Common concerns • Case Studies typescript.html

    • Typing your state • Typing your components • Typing your styles hands on!!!
  34. advantages • Code easier to understand • Code easier and

    faster to implement • Code easier to refactor • Fewer bugs advantages.html
  35. advantages • Less boilerplate tests • Aids the developer in

    having the correct workflow advantages.html
  36. concerns concerns.html • “It will harm our recruitment” • “On-boarding

    will take more time” • “By choosing TypeScript, we might end up being locked with some legacy tool, that nobody will support in the future”
  37. me.html I am… Matheus Albuquerque
 Sr. Software Engineer, Front-End @STRV


    Web Development Track @BLN @ythecombinator www.ythecombinator.space [email protected]