Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "igris", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A small, simple, and type-safe state management solution for React and React Native.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,18 +32,22 @@ # Igris | ||
import React from 'react'; | ||
import { useAStore, createStore } from 'igris'; | ||
import { createStore, createState } from 'igris'; | ||
// **Store Example** | ||
// Create a new instance of the store with initial state and actions | ||
const counterStore = createStore( | ||
{ count: 0 }, // Initial state | ||
(setState, getState) => ({ | ||
// Callback function to generate actions | ||
increment: () => setState({ count: getState().count + 1 }), // Action to increment count | ||
decrement: () => setState({ count: getState().count - 1 }), // Action to decrement count | ||
export const useCount = createStore( | ||
{ count: 0 }, | ||
({ set, get }) => ({ | ||
increment: () => { | ||
set({ count: get().count + 1 }); | ||
}, | ||
decrement: () => { | ||
set({ count: get().count - 1 }); | ||
}, | ||
}) | ||
); | ||
//without selector | ||
// Without selector | ||
const CounterComponent = () => { | ||
const { count, decrement, increment } = useAStore(counterStore); | ||
const { count, decrement, increment } = useCount(); | ||
@@ -59,5 +63,5 @@ return ( | ||
//with selector get state | ||
// With selector to get state | ||
const CountDisplayComponent = () => { | ||
const count = useAStore(counterStore, (state) => state.count); | ||
const count = useCount((state) => state.count); | ||
@@ -71,9 +75,7 @@ return ( | ||
//with selector get actions | ||
// With selector to get actions | ||
const CountActionsComponent = () => { | ||
const increment = useCount((state) => state.increment); | ||
const decrement = useCount((state) => state.decrement); | ||
const increment = useAStore(counterStore, (state) => state.increment); | ||
const decrement = useAStore(counterStore, (state) => state.decrement); | ||
return ( | ||
@@ -87,2 +89,17 @@ <div> | ||
// **State Example** | ||
export const useDarkTheme = createState(true); | ||
const ThemeComponent = () => { | ||
const [isDark, setDark] = useDarkTheme(); | ||
return ( | ||
<div> | ||
<p>Current Theme: {isDark ? 'Dark' : 'Light'}</p> | ||
<button onClick={() => setDark(true)}>DARK</button> | ||
<button onClick={() => setDark(false)}>LIGHT</button> | ||
</div> | ||
); | ||
} | ||
``` | ||
@@ -89,0 +106,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158732
116