Giter Club home page Giter Club logo

prop-drilling's Introduction

prop-drilling

This is a companion repo to the blog post Repeat yourself a little less: Strategies for mitigating prop drilling with React and TypeScript. It demonstrates the problem of prop drilling in React+TypeScript, then shows several possible approaches for mitigating it.

Here's what the demo app looks like:

The demo app

Here are the variations on the theme:

Technique Demo Lines Notes
Initial Example codepen 64 Starter app with two synchronized counters
Fully Threaded codepen 99 Going up to three counters illustrates the problem of prop drilling.
Fewer Components codepen 46 By inlining separate components, we dramatically reduce the amount of code.
Single Object codepen 88 Merging related props into a single object eliminates intermediate components' need to know the details of that object.
Use Children codepen 72 By passing children to a container component, we free it from having to understand its children's props.
Context API codepen 91 React's Context API provides a built-in way to do dependency injection.
Pick Props codepen 93 A TypeScript-friendly way to have one component "pick" props from another, both for types and at runtime.

Do you have another way you like to deal with prop drilling? Send a PR to add it!

Development

yarn
yarn type-check

prop-drilling's People

Contributors

danvk avatar

Stargazers

Ibraheem Shawhnee avatar Ben Lucas avatar Kevin Nolan avatar Aaron McAdam avatar

Watchers

 avatar James Cloos avatar  avatar

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.