MCPcopy
hub / github.com/styletron/styletron / checkNoopEngine

Function checkNoopEngine

packages/styletron-react/src/index.tsx:115–138  ·  view source on GitHub ↗
(engine: StandardEngine)

Source from the content-addressed store, hash-verified

113};
114
115function checkNoopEngine(engine: StandardEngine) {
116 // if no engine provided, we default to no-op, handy for tests
117 // however, print a warning in other envs
118 if (process.env.NODE_ENV !== "test") {
119 engine === noopEngine &&
120 // eslint-disable-next-line no-console
121 console.warn(
122 __DEV__
123 ? `
124Styletron has been switched to a no-op (test) mode.
125
126A Styletron styled component was rendered, but no Styletron engine instance was provided in React context.
127
128Did you forget to provide a Styletron engine instance to React context via using the Styletron provider component?
129
130Note: Providers and Consumers must come from the exact same React.createContext call to work.
131If your app has multiple instances of the "styletron-react" package in your node_module tree,
132your Provider may be coming from a different React.createContext call, which means the styled components
133will not recieve the provided engine instance. This scenario can arise, for example, when using "npm link".
134`
135 : `Styletron Provider is not set up. Defaulting to no-op.`,
136 );
137 }
138}
139
140export function useStyletron(): [(style: StyleObject) => string] {
141 const styletronEngine: StandardEngine = React.useContext(StyletronContext);

Callers 2

useStyletronFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected