Gathering detailed insights and metrics for tiny-context
Gathering detailed insights and metrics for tiny-context
Gathering detailed insights and metrics for tiny-context
Gathering detailed insights and metrics for tiny-context
This library for Context API of React Hooks. Easily create a context with a state and an action to update it.
npm install tiny-context
Typescript
Module System
Node Version
NPM Version
TypeScript (86.53%)
JavaScript (13.47%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,221 Commits
2 Watchers
30 Branches
2 Contributors
Updated on Jan 15, 2025
Latest Version
1.8.2
Package Id
tiny-context@1.8.2
Unpacked Size
54.35 kB
Size
9.95 kB
File Count
10
NPM Version
6.14.2
Node Version
12.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
31
This library for Context API of React Hooks. Easily create a context with a state and an action to update it.
Requires React 16.8.3 or later.
npm install tiny-context
This library wraps the React Context API and supports creating contexts with { state: { ... }, actions: { ... } }
.
Define State
.
1type CounterState = { count: number };
Define actions
that takes State
as the first argument and returns State
. actions
can also be created on a class-base.
1const actions = { 2 increment: (state: CounterState, amount: number) => ({ ...state, count: state.count + amount }), 3};
Call createTinyContext
to create Provider
and useContext
from actions
. Specify the State
and actions
for the type argument.
1const { Provider, useContext } = createTinyContext<CounterState, typeof actions>(actions);
(option) If you use the actions
method, you only need to specify State
type argument.
1const { Provider, useContext } = createTinyContext<CounterState>().actions(actions);
Can be used like the React Context API :)
1const Buttons = () => { 2 const { 3 actions: { increment }, 4 } = useContext(); 5 return <button onClick={() => increment(1)}>+</button>; 6}; 7 8const Display = () => { 9 const { 10 state: { count }, 11 } = useContext(); 12 return <span>{count}</span>; 13}; 14 15const CounterApp = () => ( 16 <Provider value={{ count: 0 }}> 17 <Buttons /> 18 <Display /> 19 </Provider> 20);
Class-based actions, Async action, Async generator action, abortable request, and Todo App examples.
https://benishouga.github.io/tiny-context/
Create Provider and useContext from Actions implementations. Actions implementation methods require the first argument to be State
and the return value to be State
(or Promise
, Async Generator
).
Specify the State
and the Actions
interface for the type argument.
1import { createTinyContext } from 'tiny-context'; 2 3type CounterState = { count: number; }; 4class CounterActions { 5 increment: (state: CounterState, amount: number) => ({ ...state, count: state.count + amount }) 6 decrement: (state: CounterState, amount: number) => ({ ...state, count: state.count - amount }) 7} 8const { Provider, useContext } = createTinyContext<CounterState, CounterActions>(new CounterActions());
If the actions
method is used, the type argument of Actions
can be omitted.
1const { Provider, useContext } = createTinyContext<CounterState>().actions(new CounterActions());
Provider
is same as Provider of React
.
Supply an initial value for value
.
1const SomeApp = () => ( 2 <Provider value={{ count: 0 }}> 3 <SomeConsumer /> 4 </Provider> 5);
useContext
is hooks used on a consumer. Not need arguments. You will get an object of { state: {...}, acitons: {...} }
.
Function arguments are inherited from the second and subsequent arguments of the previously defined Action. The return value is a uniform Promise<State>
.
1const SomeConsumer = () => { 2 const { 3 state: {...}, 4 actions: {...} 5 } = useContext(); 6 7};
Class for managing the State
. (createTinyContext
uses this.)
Given a State
and Actions
to change State
, Actions
are sequenced to prevent invalid State
.
State
to managed.Actions
to change State
. Actions
implementation methods require the first argument to be State
and the return value to be State
(or Promise
, Async Generator
).State
.Actions
to change State
.1type State = { count: number }; 2const store = new Store( 3 { count: 0 }, 4 { increment: (state: State, amount: number) => ({ count: state.count + amount }) } 5); 6const { increment } = store.actions; 7await increment(1); 8const { count } = store.state; 9console.log(count); // => 1
Current State
.
Actions
to change State
.
Function arguments are inherited from the second and subsequent arguments of the previously defined Action. The return value is a uniform Promise<State>
.
Adds a change listener.
I make heavy use of Google Translate. Please tell me if my English is wrong :)
MIT License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
62 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More