Giter Site home page Giter Site logo

multi-package-context's Introduction

Multi-package context

An attempt to create a context that can be included across packages in support of a plugin-style architecture.

This is a monorepo using Lerna and NPM workspaces. All of the packages are Typescript and are built with Rollup. To set up and start the server, run:

npm run bootstrap
npm run build
npm run start

Or just use the quickstart command, which does all of those things in that order.

npm run quickstart

Background

There are four packages here:

  • app - A Nextjs application that displays the components from the other packages. Not much to see here.
  • context-proj - A project that contains both the context provider (intended to be used in all other applications) as well as an InternalConsumer component. The InternalConsumer component is identical to the context-consumer1/2 components, except it just resides in the same project as the context. The context just consists of a string variable and a function (someString and someFunction).
  • context-consumer1 - A project that exports the MyConsumer1 component, which consumes the context from context-proj and displays its values.
  • context-consumer2 - Same as context-consumer1 except the component is named MyConsumer2.

What Happens

When the MyContext.Provider element is created in app, only InternalConsumer seems to get the context appropriately. Both MyConsumer1 and MyConsumer2 fall back on the default MyContext object.

What Should Happen

All three context consumers should use the same context.

The Question

What's the "correct" way to implement this paradigm with useContext?

multi-package-context's People

Contributors

cogsandgears avatar

Watchers

 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.