Gathering detailed insights and metrics for @lodado/namespace-core
Gathering detailed insights and metrics for @lodado/namespace-core
Namespace Store for React is a simple and powerful state management library designed to solve issues with nested contexts in React applications. 🌟
npm install @lodado/namespace-core
Typescript
Module System
Node Version
NPM Version
68
Supply Chain
99.2
Quality
82.9
Maintenance
100
Vulnerability
100
License
TypeScript (85.41%)
JavaScript (14.46%)
Shell (0.13%)
Total Downloads
464
Last Day
8
Last Week
44
Last Month
286
Last Year
464
2 Stars
80 Commits
1 Watching
5 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.3
Package Id
@lodado/namespace-core@1.0.3
Unpacked Size
12.04 kB
Size
5.29 kB
File Count
23
NPM Version
10.2.3
Node Version
18.19.0
Publised On
02 Dec 2024
Cumulative downloads
Total Downloads
Last day
-33.3%
8
Compared to previous day
Last week
-31.3%
44
Compared to previous week
Last month
60.7%
286
Compared to previous month
Last year
0%
464
Compared to previous year
@lodado/namespace-core
is a lightweight and flexible library designed for state management in React applications. It provides the NamespaceStore
class, which serves as a foundational tool for creating custom state stores using JavaScript's Proxy API. By extending NamespaceStore
, developers can define application state and actions in a structured and scalable manner.
more information >>
https://github.com/lodado/react-namespace/tree/publish
To utilize @lodado/namespace-core
, you start by creating a store class that extends NamespaceStore
. This custom store will hold your application's state and provide methods to modify it.
1import { NamespaceStore } from '@lodado/namespace-core'; 2 3interface AppState { 4 user: { 5 name: string; 6 email: string; 7 }; 8 theme: 'light' | 'dark'; 9} 10 11class AppStore extends NamespaceStore<AppState> { 12 constructor(initialState: AppState) { 13 super(initialState); 14 } 15 16 // Actions to modify the state 17 setUser(user: AppState['user']) { 18 this.state.user = user; 19 } 20 21 toggleTheme() { 22 this.state.theme = this.state.theme === 'light' ? 'dark' : 'light'; 23 } 24} 25 26// Instantiate the global store 27const globalStore = new AppStore({ 28 user: { 29 name: 'John Doe', 30 email: 'john.doe@example.com', 31 }, 32 theme: 'light', 33});
Within your extended NamespaceStore
, you can define methods that act upon the state. These actions encapsulate the logic for updating state properties.
1class CounterStore extends NamespaceStore<{ count: number }> { 2 constructor() { 3 super({ count: 0 }); 4 } 5 6 increment() { 7 this.state.count += 1; 8 } 9 10 decrement() { 11 this.state.count -= 1; 12 } 13}
@lodado/namespace-core
is particularly beneficial in the following scenarios:
Install the package using npm or yarn:
1npm install @lodado/namespace-core 2# or 3yarn add @lodado/namespace-core
MIT License
By focusing on the core functionalities provided by @lodado/namespace-core
, developers can create efficient and maintainable state management solutions tailored to their application's needs.
No vulnerabilities found.
No security vulnerabilities found.