@siberiacancode/reactuse 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"createContext.cjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, useContext, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","useContext","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":"wIAsDaA,EAAgB,CAC3BC,EAAkC,OAClCC,EAAgC,CAAA,IACD,CAC/B,MAAMC,EAAUC,EAAAA,cAGb,CACD,MAAOH,EACP,IAAK,IAAM,CAAA,CAAC,CACb,EAEDE,EAAQ,YAAcD,EAAQ,KAI9B,SAASG,EAAoBC,EAAuC,CAC5D,MAAAC,EAAUC,aAAWL,CAAO,EAE9B,GAAA,CAACI,GAAWL,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,OAAKI,EAIEA,EAASC,EAAQ,KAAc,EAH7BA,CAG6B,CAiBjC,MAAA,CACL,UAAAF,EACA,SAAUF,EACV,SAjBe,CAAC,CAAE,SAAAM,EAAU,aAAAC,KAAyC,CACrE,KAAM,CAACC,EAASC,CAAU,EAAIC,EAAAA,SAA4BH,GAAgBT,CAAY,EAEhFa,EAAQC,EAAA,QACZ,KAAO,CACL,MAAOJ,EACP,IAAKC,CAAA,GAEP,CAACD,CAAO,CACV,EAEO,OAAAK,EAAA,IAACb,EAAQ,CAAA,MAAAW,EAAe,SAAAL,CAAS,CAAA,CAC1C,CAMA,CACF"}
1
+ {"version":3,"file":"createContext.cjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, useContext, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children?: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","useContext","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":"wIAsDaA,EAAgB,CAC3BC,EAAkC,OAClCC,EAAgC,CAAA,IACD,CAC/B,MAAMC,EAAUC,EAAAA,cAGb,CACD,MAAOH,EACP,IAAK,IAAM,CAAA,CAAC,CACb,EAEDE,EAAQ,YAAcD,EAAQ,KAI9B,SAASG,EAAoBC,EAAuC,CAC5D,MAAAC,EAAUC,aAAWL,CAAO,EAE9B,GAAA,CAACI,GAAWL,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,OAAKI,EAIEA,EAASC,EAAQ,KAAc,EAH7BA,CAG6B,CAiBjC,MAAA,CACL,UAAAF,EACA,SAAUF,EACV,SAjBe,CAAC,CAAE,SAAAM,EAAU,aAAAC,KAAyC,CACrE,KAAM,CAACC,EAASC,CAAU,EAAIC,EAAAA,SAA4BH,GAAgBT,CAAY,EAEhFa,EAAQC,EAAA,QACZ,KAAO,CACL,MAAOJ,EACP,IAAKC,CAAA,GAEP,CAACD,CAAO,CACV,EAEO,OAAAK,EAAA,IAACb,EAAQ,CAAA,MAAAW,EAAe,SAAAL,CAAS,CAAA,CAC1C,CAMA,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"createContext.mjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, useContext, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","useContext","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":";;AAsDO,MAAMA,IAAgB,CAC3BC,IAAkC,QAClCC,IAAgC,CAAA,MACD;AAC/B,QAAMC,IAAUC,EAGb;AAAA,IACD,OAAOH;AAAA,IACP,KAAK,MAAM;AAAA,IAAA;AAAA,EAAC,CACb;AAED,EAAAE,EAAQ,cAAcD,EAAQ;AAI9B,WAASG,EAAoBC,GAAuC;AAC5D,UAAAC,IAAUC,EAAWL,CAAO;AAE9B,QAAA,CAACI,KAAWL,EAAQ;AACtB,YAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC;AAG/E,WAAKI,IAIEA,EAASC,EAAQ,KAAc,IAH7BA;AAAA,EAG6B;AAiBjC,SAAA;AAAA,IACL,WAAAF;AAAA,IACA,UAAUF;AAAA,IACV,UAjBe,CAAC,EAAE,UAAAM,GAAU,cAAAC,QAAyC;AACrE,YAAM,CAACC,GAASC,CAAU,IAAIC,EAA4BH,KAAgBT,CAAY,GAEhFa,IAAQC;AAAA,QACZ,OAAO;AAAA,UACL,OAAOJ;AAAA,UACP,KAAKC;AAAA,QAAA;AAAA,QAEP,CAACD,CAAO;AAAA,MACV;AAEO,aAAA,gBAAAK,EAACb,GAAQ,EAAA,OAAAW,GAAe,UAAAL,EAAS,CAAA;AAAA,IAC1C;AAAA,EAMA;AACF;"}
1
+ {"version":3,"file":"createContext.mjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, useContext, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children?: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","useContext","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":";;AAsDO,MAAMA,IAAgB,CAC3BC,IAAkC,QAClCC,IAAgC,CAAA,MACD;AAC/B,QAAMC,IAAUC,EAGb;AAAA,IACD,OAAOH;AAAA,IACP,KAAK,MAAM;AAAA,IAAA;AAAA,EAAC,CACb;AAED,EAAAE,EAAQ,cAAcD,EAAQ;AAI9B,WAASG,EAAoBC,GAAuC;AAC5D,UAAAC,IAAUC,EAAWL,CAAO;AAE9B,QAAA,CAACI,KAAWL,EAAQ;AACtB,YAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC;AAG/E,WAAKI,IAIEA,EAASC,EAAQ,KAAc,IAH7BA;AAAA,EAG6B;AAiBjC,SAAA;AAAA,IACL,WAAAF;AAAA,IACA,UAAUF;AAAA,IACV,UAjBe,CAAC,EAAE,UAAAM,GAAU,cAAAC,QAAyC;AACrE,YAAM,CAACC,GAASC,CAAU,IAAIC,EAA4BH,KAAgBT,CAAY,GAEhFa,IAAQC;AAAA,QACZ,OAAO;AAAA,UACL,OAAOJ;AAAA,UACP,KAAKC;AAAA,QAAA;AAAA,QAEP,CAACD,CAAO;AAAA,MACV;AAEO,aAAA,gBAAAK,EAACb,GAAQ,EAAA,OAAAW,GAAe,UAAAL,EAAS,CAAA;AAAA,IAC1C;AAAA,EAMA;AACF;"}
@@ -16,7 +16,7 @@ export interface ContextValue<Value> {
16
16
  /** The provider props type */
17
17
  export interface ProviderProps<Value> {
18
18
  /** The children */
19
- children: ReactNode;
19
+ children?: ReactNode;
20
20
  /** The initial value */
21
21
  initialValue?: Value;
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",
@@ -68,17 +68,17 @@
68
68
  "@testing-library/dom": "^10.4.0",
69
69
  "@testing-library/react": "^16.3.0",
70
70
  "@types/dom-speech-recognition": "^0.0.6",
71
- "@types/react": "^19.1.5",
71
+ "@types/react": "^19.1.6",
72
72
  "@types/react-dom": "^19.1.5",
73
73
  "@types/web-bluetooth": "^0.0.21",
74
- "@vitejs/plugin-react": "^4.5.0",
74
+ "@vitejs/plugin-react": "^4.5.1",
75
75
  "core-js": "^3.42.0",
76
76
  "react": "^19.1.0",
77
77
  "react-dom": "^19.1.0",
78
78
  "shx": "^0.4.0",
79
79
  "vite": "^6.3.5",
80
80
  "vite-plugin-dts": "^4.5.4",
81
- "vitest": "^3.1.4"
81
+ "vitest": "^3.2.1"
82
82
  },
83
83
  "lint-staged": {
84
84
  "*.{js,ts,tsx}": [