Open Download opened 5 years ago
It might be helpful to look at some actual projects, but I can understand if it's too much :)
Thanks for the PR. I'll try to merge it as soon as possible
I created a new PR. I processed your feedback and implemented the log
option as well.
I am getting this warning in the console:
The message is clear enough, but in my case this is not an issue and I would like to suppress this warning.
I'll describe my use case below and show some example code, but the gist of it is: in my case, the use of context is optional and it is expected that it might not be provided. So I would like the option to suppress the warning.
Would you accept a PR? EDIT: Too late, I already created one :) #25
Background
I am using
preact-context
to create a theming solution based on CSS modules. The way it works is that the components will by default render the default class names, but you can load the CSS via CSS Modules and pass the module def to a Provider and the components will pick it up and use the modified class names.The way I did this was to have a default definition in each component that contains the unmodified class names just like they appear in my CSS.
E.g:
After loading the CSS through CSS Modules, this will produce a module definition with mangled class names (to provide scoping), that looks like this:
The user of my library can wrap the components in a theme Provider and provide the mangled names so the components will use those names i.s.o the default ones.
The components all use a Consumer defined in a common file and when the user needs a Provider, he gets it from this same file:
theme.jsx
The components use the Consumer to try to get the property
classes
from the context, defaulting it to an empty object. They then merge theclasses
over thedefaultClasses
and use the resulting definition:card.jsx
This all works like a charm, except that I get this annoying warning, even in the production build.