Home

Awesome

<div> <h1 align="center"><a href="https://www.epicreact.dev/modules/advanced-react-patterns-v1/advanced-react-patterns-welcome">🀯 Advanced React Patterns πŸš€ EpicReact.Dev</a></h1> <strong> Learn how to build simple and flexible React Components and Hooks using modern patterns </strong> <p> Not only learn great patterns you can use but also the strengths and weaknesses of each, so you know which to reach for to provide your custom hooks and components the flexibility and power you need. </p> <a href="https://epicreact.dev"> <img alt="Learn React from Start to Finish" src="https://kentcdodds.com/images/epicreact-promo/er-1.gif" /> </a> </div> <hr /> <!-- prettier-ignore-start -->

Build Status All Contributors GPL 3.0 License Code of Conduct Gitpod ready-to-code

<!-- prettier-ignore-end -->

Prerequisites

NOTE: The EpicReact.dev videos were recorded with React version ^16.13 and all material in this repo has been updated to React version ^18. Differences are minor and any relevant differences are noted in the instructions.

Quick start

It's recommended you run everything in the same environment you work in every day, but if you don't want to set up the repository locally, you can get started in one click with Gitpod, CodeSandbox, or by following the video demo instructions for GitHub Codespaces.

Open in Gitpod

For a local development environment, follow the instructions below

System Requirements

All of these must be available in your PATH. To verify things are set up properly, you can run this:

git --version
node --version
npm --version

If you have trouble with any of these, learn more about the PATH environment variable and how to fix it here for windows or mac/linux.

Setup

If you want to commit and push your work as you go, you'll want to fork first and then clone your fork rather than this repo directly.

After you've made sure to have the correct things (and versions) installed, you should be able to just run a few commands to get set up:

git clone https://github.com/kentcdodds/advanced-react-patterns.git
cd advanced-react-patterns
node setup

This may take a few minutes. It will ask you for your email. This is optional and just automatically adds your email to the links in the project to make filling out some forms easier.

If you get any errors, please read through them and see if you can find out what the problem is. If you can't work it out on your own then please file an issue and provide all the output from the commands you ran (even if it's a lot).

If you can't get the setup script to work, then just make sure you have the right versions of the requirements listed above, and run the following commands:

npm install
npm run validate

If you are still unable to fix issues and you know how to use Docker 🐳 you can setup the project with the following command:

docker-compose up

Running the app

To get the app up and running (and really see if it worked), run:

npm start

This should start up your browser. If you're familiar, this is a standard react-scripts application.

You can also open the deployment of the app on Netlify.

Running the tests

npm test

This will start Jest in watch mode. Read the output and play around with it. The tests are there to help you reach the final version, however sometimes you can accomplish the task and the tests still fail if you implement things differently than I do in my solution, so don't look to them as a complete authority.

Exercises

The purpose of the exercise is not for you to work through all the material. It's intended to get your brain thinking about the right questions to ask me as I walk through the material.

Helpful Emoji 🐨 πŸ’° πŸ’― πŸ“ πŸ¦‰ πŸ“œ πŸ’£ πŸ’ͺ 🏁 πŸ‘¨β€πŸ’Ό 🚨

Each exercise has comments in it to help you get through the exercise. These fun emoji characters are here to help you.

Contributors

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://kentcdodds.com"><img src="https://avatars.githubusercontent.com/u/1500684?v=3?s=100" width="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=kentcdodds" title="Code">πŸ’»</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=kentcdodds" title="Documentation">πŸ“–</a> <a href="#infra-kentcdodds" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=kentcdodds" title="Tests">⚠️</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/FWeinb"><img src="https://avatars0.githubusercontent.com/u/1250430?v=4?s=100" width="100px;" alt="FWeinb"/><br /><sub><b>FWeinb</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/issues?q=author%3AFWeinb" title="Bug reports">πŸ›</a> <a href="#ideas-FWeinb" title="Ideas, Planning, & Feedback">πŸ€”</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/dlannoye"><img src="https://avatars2.githubusercontent.com/u/1383720?v=4?s=100" width="100px;" alt="David Lannoye"/><br /><sub><b>David Lannoye</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/issues?q=author%3Adlannoye" title="Bug reports">πŸ›</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=dlannoye" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/colinrcummings"><img src="https://avatars2.githubusercontent.com/u/9815009?s=460&v=4?s=100" width="100px;" alt="Colin Cummings"/><br /><sub><b>Colin Cummings</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=colinrcummings" title="Code">πŸ’»</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=colinrcummings" title="Tests">⚠️</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/bkoltai"><img src="https://avatars2.githubusercontent.com/u/464764?v=4?s=100" width="100px;" alt="Benji Koltai"/><br /><sub><b>Benji Koltai</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=bkoltai" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://baggasumit.github.io"><img src="https://avatars1.githubusercontent.com/u/1779959?v=4?s=100" width="100px;" alt="Sumit Bagga"/><br /><sub><b>Sumit Bagga</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=baggasumit" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/Tarabyte"><img src="https://avatars0.githubusercontent.com/u/2027010?v=4?s=100" width="100px;" alt="Yury Tarabanko"/><br /><sub><b>Yury Tarabanko</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=Tarabyte" title="Code">πŸ’»</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="http://www.wendtedesigns.com/"><img src="https://avatars2.githubusercontent.com/u/5779538?v=4?s=100" width="100px;" alt="Alex Wendte"/><br /><sub><b>Alex Wendte</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=themostcolm" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://twitter.com/CompuIves"><img src="https://avatars3.githubusercontent.com/u/587016?v=4?s=100" width="100px;" alt="Ives van Hoorne"/><br /><sub><b>Ives van Hoorne</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=CompuIves" title="Code">πŸ’»</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=CompuIves" title="Tests">⚠️</a></td> <td align="center" valign="top" width="14.28%"><a href="http://team.thebrain.pro"><img src="https://avatars1.githubusercontent.com/u/4002543?v=4?s=100" width="100px;" alt="Łukasz Gandecki"/><br /><sub><b>Łukasz Gandecki</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=lgandecki" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/deniztetik"><img src="https://avatars0.githubusercontent.com/u/14167019?v=4?s=100" width="100px;" alt="Deniz Tetik"/><br /><sub><b>Deniz Tetik</b></sub></a><br /><a href="#content-deniztetik" title="Content">πŸ–‹</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/Ruffeng"><img src="https://avatars1.githubusercontent.com/u/18511772?v=4?s=100" width="100px;" alt="Ruffeng"/><br /><sub><b>Ruffeng</b></sub></a><br /><a href="#content-Ruffeng" title="Content">πŸ–‹</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=Ruffeng" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://stackshare.io/jdorfman/decisions"><img src="https://avatars1.githubusercontent.com/u/398230?v=4?s=100" width="100px;" alt="Justin Dorfman"/><br /><sub><b>Justin Dorfman</b></sub></a><br /><a href="#fundingFinding-jdorfman" title="Funding Finding">πŸ”</a></td> <td align="center" valign="top" width="14.28%"><a href="http://alexmunoz.github.io"><img src="https://avatars3.githubusercontent.com/u/3093946?v=4?s=100" width="100px;" alt="Alex Munoz"/><br /><sub><b>Alex Munoz</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=AlexMunoz" title="Documentation">πŸ“–</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/marcosvega91"><img src="https://avatars2.githubusercontent.com/u/5365582?v=4?s=100" width="100px;" alt="Marco Moretti"/><br /><sub><b>Marco Moretti</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=marcosvega91" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/emipc"><img src="https://avatars1.githubusercontent.com/u/26004903?v=4?s=100" width="100px;" alt="Emili"/><br /><sub><b>Emili</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=emipc" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/balavishnuvj"><img src="https://avatars3.githubusercontent.com/u/13718688?v=4?s=100" width="100px;" alt="balavishnuvj"/><br /><sub><b>balavishnuvj</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=balavishnuvj" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/pritamsangani/"><img src="https://avatars3.githubusercontent.com/u/22857896?v=4?s=100" width="100px;" alt="Pritam Sangani"/><br /><sub><b>Pritam Sangani</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=PritamSangani" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="http://linkedin.com/in/katarzynakosturek/"><img src="https://avatars3.githubusercontent.com/u/36547835?v=4?s=100" width="100px;" alt="Kasia Kosturek"/><br /><sub><b>Kasia Kosturek</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=kocvrek" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/emzoumpo"><img src="https://avatars2.githubusercontent.com/u/2103443?v=4?s=100" width="100px;" alt="Emmanouil Zoumpoulakis"/><br /><sub><b>Emmanouil Zoumpoulakis</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=emzoumpo" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://peter.hozak.info/"><img src="https://avatars0.githubusercontent.com/u/1087670?v=4?s=100" width="100px;" alt="Peter HozΓ‘k"/><br /><sub><b>Peter HozΓ‘k</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=Aprillion" title="Code">πŸ’»</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/nawok"><img src="https://avatars3.githubusercontent.com/u/159773?v=4?s=100" width="100px;" alt="Pavel Fomchenkov"/><br /><sub><b>Pavel Fomchenkov</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=nawok" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://www.seemaullal.com"><img src="https://avatars0.githubusercontent.com/u/8728285?v=4?s=100" width="100px;" alt="Seema Ullal"/><br /><sub><b>Seema Ullal</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=seemaullal" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://git.io/JfYj5"><img src="https://avatars0.githubusercontent.com/u/25733135?v=4?s=100" width="100px;" alt="Patrick Clery"/><br /><sub><b>Patrick Clery</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=patrickclery" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/degeens"><img src="https://avatars2.githubusercontent.com/u/33414262?v=4?s=100" width="100px;" alt="Stijn Geens"/><br /><sub><b>Stijn Geens</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=degeens" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://michaeldeboey.be"><img src="https://avatars3.githubusercontent.com/u/6643991?v=4?s=100" width="100px;" alt="MichaΓ«l De Boey"/><br /><sub><b>MichaΓ«l De Boey</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=MichaelDeBoey" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.daleseo.com"><img src="https://avatars1.githubusercontent.com/u/5466341?v=4?s=100" width="100px;" alt="Dale Seo"/><br /><sub><b>Dale Seo</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=DaleSeo" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://bobbywarner.com"><img src="https://avatars0.githubusercontent.com/u/554961?v=4?s=100" width="100px;" alt="Bobby Warner"/><br /><sub><b>Bobby Warner</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=bobbywarner" title="Code">πŸ’»</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="https://www.sophiabrandt.com"><img src="https://avatars0.githubusercontent.com/u/16630701?v=4?s=100" width="100px;" alt="Sophia Brandt"/><br /><sub><b>Sophia Brandt</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=sophiabrandt" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/ph08n1x"><img src="https://avatars.githubusercontent.com/u/4249732?v=4?s=100" width="100px;" alt="ph08n1x"/><br /><sub><b>ph08n1x</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=ph08n1x" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.suhas010.com"><img src="https://avatars.githubusercontent.com/u/8597576?v=4?s=100" width="100px;" alt="Suhas R More"/><br /><sub><b>Suhas R More</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=Suhas010" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/0xnoob"><img src="https://avatars.githubusercontent.com/u/49793844?v=4?s=100" width="100px;" alt="0xnoob"/><br /><sub><b>0xnoob</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=0xnoob" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="http://pavlos.dev"><img src="https://avatars.githubusercontent.com/u/100233?v=4?s=100" width="100px;" alt="Pavlos Vinieratos"/><br /><sub><b>Pavlos Vinieratos</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=pvinis" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/infoxicator"><img src="https://avatars.githubusercontent.com/u/17012976?v=4?s=100" width="100px;" alt="Ruben Casas"/><br /><sub><b>Ruben Casas</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=infoxicator" title="Code">πŸ’»</a> <a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=infoxicator" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/marioleed"><img src="https://avatars.githubusercontent.com/u/1763448?v=4?s=100" width="100px;" alt="Mario Sannum"/><br /><sub><b>Mario Sannum</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=marioleed" title="Code">πŸ’»</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="https://wrongabhishek.com"><img src="https://avatars.githubusercontent.com/u/47311875?v=4?s=100" width="100px;" alt="Abhishek Rawat"/><br /><sub><b>Abhishek Rawat</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=AbePlays" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://fullchee.com"><img src="https://avatars.githubusercontent.com/u/11246258?v=4?s=100" width="100px;" alt="Fullchee Zhang"/><br /><sub><b>Fullchee Zhang</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=Fullchee" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/YaseenAlGailani"><img src="https://avatars.githubusercontent.com/u/23329119?v=4?s=100" width="100px;" alt="Yaseen"/><br /><sub><b>Yaseen</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=YaseenAlGailani" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://mangovoice.com"><img src="https://avatars.githubusercontent.com/u/2466729?v=4?s=100" width="100px;" alt="Jeff Potter"/><br /><sub><b>Jeff Potter</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=jpotts18" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/kenneth-gray"><img src="https://avatars.githubusercontent.com/u/10341832?v=4?s=100" width="100px;" alt="Kenny Gray"/><br /><sub><b>Kenny Gray</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/issues?q=author%3Akenneth-gray" title="Bug reports">πŸ›</a></td> <td align="center" valign="top" width="14.28%"><a href="http://jorgearuv.dev"><img src="https://avatars.githubusercontent.com/u/7416811?v=4?s=100" width="100px;" alt="Jorge Ruvalcaba"/><br /><sub><b>Jorge Ruvalcaba</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=jorgeruvalcaba" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://creador.dev"><img src="https://avatars.githubusercontent.com/u/40248406?v=4?s=100" width="100px;" alt="Pawan Kumar"/><br /><sub><b>Pawan Kumar</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=creador-dev" title="Documentation">πŸ“–</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="http://junagao.com"><img src="https://avatars.githubusercontent.com/u/615616?v=4?s=100" width="100px;" alt="juliane nagao"/><br /><sub><b>juliane nagao</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=junagao" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="http://www.ianjmacintosh.com"><img src="https://avatars.githubusercontent.com/u/1103259?v=4?s=100" width="100px;" alt="Ian MacIntosh"/><br /><sub><b>Ian MacIntosh</b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=ianjmacintosh" title="Documentation">πŸ“–</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/Creeland"><img src="https://avatars.githubusercontent.com/u/518406?v=4?s=100" width="100px;" alt="Creeland A. Provinsal "/><br /><sub><b>Creeland A. Provinsal </b></sub></a><br /><a href="https://github.com/kentcdodds/advanced-react-patterns/commits?author=Creeland" title="Documentation">πŸ“–</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!

Workshop Feedback

Each exercise has an Elaboration and Feedback link. Please fill that out after the exercise and instruction.

At the end of the workshop, please go to this URL to give overall feedback. Thank you! https://kcd.im/arp-ws-feedback

<!-- prettier-ignore-start --> <!-- prettier-ignore-end -->