diff --git a/src/index.tsx b/src/index.tsx index 1ee9a36..355eefe 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,12 +1,14 @@ import * as React from "react"; import { SplitValueFunction, ContextHookReturn } from "./types"; -const NO_PROVIDER = "CONSTATE_NO_PROVIDER" as any; +const isDev = process.env.NODE_ENV !== "production"; + +const NO_PROVIDER = "_NP_" as any; function createUseContext(context: React.Context): any { return () => { const value = React.useContext(context); - if (process.env.NODE_ENV !== "production" && value === NO_PROVIDER) { + if (isDev && value === NO_PROVIDER) { // eslint-disable-next-line no-console console.warn("[constate] Component not wrapped within a Provider."); } @@ -25,7 +27,7 @@ function constate>>( const [createMemoDeps] = splitValues; const deps = createMemoDeps && createMemoDeps(value); - if (process.env.NODE_ENV !== "production" && Array.isArray(deps)) { + if (isDev && Array.isArray(deps)) { // eslint-disable-next-line no-console console.warn( "[constate] Passing `createMemoDeps` as the second argument is deprecated.", @@ -46,7 +48,7 @@ function constate>>( ); }; - if (useValue.name) { + if (isDev && useValue.name) { Context.displayName = `${useValue.name}.Context`; Provider.displayName = `${useValue.name}.Provider`; } @@ -84,7 +86,7 @@ function constate>>( return children; }; - if (useValue.name) { + if (isDev && useValue.name) { SplitProvider.displayName = `${useValue.name}.Provider`; } diff --git a/test/index.test.tsx b/test/index.test.tsx index cd19507..9fd8ca9 100644 --- a/test/index.test.tsx +++ b/test/index.test.tsx @@ -261,7 +261,7 @@ test("without provider", () => { }; const App = () => ; const { getByText } = render(); - expect(getByText("CONSTATE_NO_PROVIDER")).toBeDefined(); + expect(getByText("_NP_")).toBeDefined(); }); test("displayName with named hook", () => {