{"id":18396283,"url":"https://github.com/realdennis/nonaction","last_synced_at":"2025-07-29T03:09:02.148Z","repository":{"id":57156745,"uuid":"170848663","full_name":"realdennis/nonaction","owner":"realdennis","description":"React State management by using Hooks.  佛系狀態管理","archived":false,"fork":false,"pushed_at":"2021-05-19T21:53:28.000Z","size":184,"stargazers_count":22,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-07T09:07:01.425Z","etag":null,"topics":["consumer","context","hooks","provider","react","redux","state","state-management"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/realdennis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-15T10:42:11.000Z","updated_at":"2022-03-06T03:47:00.000Z","dependencies_parsed_at":"2022-08-30T05:32:41.322Z","dependency_job_id":null,"html_url":"https://github.com/realdennis/nonaction","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/realdennis/nonaction","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fnonaction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fnonaction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fnonaction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fnonaction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realdennis","download_url":"https://codeload.github.com/realdennis/nonaction/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realdennis%2Fnonaction/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267621606,"owners_count":24116902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consumer","context","hooks","provider","react","redux","state","state-management"],"created_at":"2024-11-06T02:13:19.200Z","updated_at":"2025-07-29T03:09:02.088Z","avatar_url":"https://github.com/realdennis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nonaction\n\n[![Build Status](https://travis-ci.org/realdennis/nonaction.svg?branch=master)](https://travis-ci.org/realdennis/nonaction)\n[![Coverage Status](https://coveralls.io/repos/github/realdennis/nonaction/badge.svg?branch=master)](https://coveralls.io/github/realdennis/nonaction?branch=master)\n[![Join the chat at https://gitter.im/nonaction-community/community](https://badges.gitter.im/nonaction-community/community.svg)](https://gitter.im/nonaction-community/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\n[中文介紹](https://github.com/realdennis/nonaction/blob/master/Chinese.md)\n\n**Nonaction** State Management [Demo](https://codesandbox.io/s/03q5n1vp0)\n\u003cbr/\u003e\n![Nonaction](https://i.imgur.com/G5iN0D2.png)\n\n---\n\n~~No Action No Reducer No Middleware It will be managed when time comes~~\n\n1.  Share state by wrote Hooks and wrapped in container\n2.  **nonaction** will give you ~~a pair of wings~~ `useProvided`\n3.  using hook in Child Components\n\nThis repository is inspired by [unstated](https://github.com/jamiebuilds/unstated), but not really similar, what I actually do is merge the Context Provider, Proxy the root context value, return the relative Container's state.\n\n## Installation\n\n```sh\n$ npm install nonaction\n```\n\n## Usage\n\n```sh\n└── src\n    ├── App.jsx\n    ├── Component\n    │   └── Counter.jsx\n    └── store\n        └── useCounter.js\n```\n\n_useCounter.js_\n\n```javascript\nimport { Container } from 'nonaction';\nconst initialState = 0;\nconst hook = () =\u003e {\n  const [count, setCount] = useState(initialState);\n  const add = val =\u003e setCount(count + val);\n  const sub = val =\u003e setCount(count - val);\n  return { count, add, sub };\n};\nexport default Container(hook); //remenber use Container to wrap\n```\n\n_App.jsx_\n\n```jsx\nimport { Provider } from 'nonaction';\nimport useCounter from './Store/useCounter.js';\nimport Counter from './Component/Counter';\nexport default () =\u003e {\n  return (\n    \u003cdiv id=\"App\"\u003e\n      \u003cProvider inject={[useCounter]}\u003e\n        \u003cCounter /\u003e\n      \u003c/Provider\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n_Counter.jsx_\n\n```jsx\nimport { useProvided } from 'nonaction';\nimport useCounter from '../store/useCounter';\nexport default () =\u003e {\n  const { count, add, sub } = useProvided(useCounter);\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e Count {count} \u003c/p\u003e\n      \u003cbutton onClick={() =\u003e add(1)}\u003e+\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e sub(1)}\u003e-\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n## Explanation\n\nMemorize how we use Context API？\n\n```jsx\nimport { createContext } from 'react';\nconst Context1 = createContext();\nconst demo = () =\u003e {\n  return (\n    \u003cContext1.Provider value={123}\u003e\n      \u003cChild1 /\u003e\n      \u003cChild2 /\u003e\n    \u003c/Context1.Provider\u003e\n  );\n};\n//Assume Child1 need Context1\nconst Child1 = () =\u003e {\n  return (\n    \u003c\u003e\n      \u003cContext1.Consumer\u003e{value =\u003e \u003cp\u003e{value}\u003c/p\u003e}\u003c/Context1.Consumer\u003e\n    \u003c/\u003e\n  );\n};\n```\n\nContext is greate，but **multiple Context** will be...\n\n```javascript\n    \u003cContext1.Provider\u003e\n      \u003cContext2.Provider\u003e\n        \u003cContext3.Provider\u003e\n          \u003cContext4.Provider\u003e\n            ... // Very annoying One Provider need One Consumer \n\t    ... // Context Hell\n          \u003c/Context4.Provider\u003e\n        \u003c/Context3.Provider\u003e\n      \u003c/Context2.Provider\u003e\n    \u003c/Context1.Provider\u003e\n```\n\nIn fact, You just use one Context share everything like this:\n\n```jsx\n\u003cContext1.Provider value={{stateA,stateB,stateC}} \u003e\n  \u003cChild /\u003e\n\u003c/Context1.Provider\u003e\n```\n\nBut potential danger is that every Components under Provider could be share/manipulate state, not complying **Principle_of_least_privilege**.\n\nIf there exsits Library, let you place every context in the root provider, but child components only take their Context value, it will be very convenience.\n\n```jsx\nimport { Provider } from 'nonaction';\nimport { ChildA, ChildB } from 'Component';\nimport { useCounter, useText } from './store';\nconst App = () =\u003e {\n  return (\n    \u003cProvider inject={[useCounter, useText /*...otherHooks*/]}\u003e\n      \u003cChildA /\u003e\n      \u003cChildB /\u003e\n    \u003c/Provider\u003e\n  );\n};\n\n//In ChildA\nimport useCounter from '../store/useCounter';\nexport default () =\u003e {\n  const counter = useProvided(useCounter);\n  return (\n    \u003c\u003e\n      \u003cp\u003eCount : {count}\u003c/p\u003e\n      \u003cbutton onClick={() =\u003e counter.add(1)}\u003e+\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e counter.sub(1)}\u003e-\u003c/button\u003e\n    \u003c/\u003e\n  );\n};\n\n\n//In ChildB\nimport useText from '../store/useText';\nexport default () =\u003e {\n  const text = useProvided(useText);\n  return (\n    \u003c\u003e\n      \u003cp\u003etext {text.text}\u003c/p\u003e\n      \u003cbutton onClick={text.bang}\u003ebang\u003c/button\u003e\n      \u003cbutton onClick={text.reset}\u003ereset\u003c/button\u003e\n    \u003c/\u003e\n  );\n};\n\n/* In future, if nested component also need to use counter's hooks\n * also import useCounter, and manipulate by useProivded.\n */\n\n```\n\nThat will be awesome, right?\n**That's the problem nonaction want to solve.**\n\n---\n\nLICENSE MIT © 2019 realdennis\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealdennis%2Fnonaction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealdennis%2Fnonaction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealdennis%2Fnonaction/lists"}