{"id":13802954,"url":"https://github.com/hlhr202/React-Combine-Provider","last_synced_at":"2025-05-13T15:32:04.535Z","repository":{"id":44140305,"uuid":"189013478","full_name":"hlhr202/React-Combine-Provider","owner":"hlhr202","description":"combine react providers in ease","archived":false,"fork":false,"pushed_at":"2023-01-07T05:51:47.000Z","size":3020,"stargazers_count":32,"open_issues_count":27,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T10:19:19.683Z","etag":null,"topics":["constate","hooks","react","react-context","react-hooks","react-state","redux","unstated"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/hlhr202.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-05-28T11:16:16.000Z","updated_at":"2024-03-16T04:40:01.000Z","dependencies_parsed_at":"2023-02-06T13:15:33.450Z","dependency_job_id":null,"html_url":"https://github.com/hlhr202/React-Combine-Provider","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlhr202%2FReact-Combine-Provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlhr202%2FReact-Combine-Provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlhr202%2FReact-Combine-Provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlhr202%2FReact-Combine-Provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hlhr202","download_url":"https://codeload.github.com/hlhr202/React-Combine-Provider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225130395,"owners_count":17425506,"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","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":["constate","hooks","react","react-context","react-hooks","react-state","redux","unstated"],"created_at":"2024-08-04T01:00:18.886Z","updated_at":"2024-11-18T19:31:11.821Z","avatar_url":"https://github.com/hlhr202.png","language":"TypeScript","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# React Combine Provider\n\n[![npm](https://img.shields.io/npm/v/react-combine-provider.svg)](https://www.npmjs.com/package/react-combine-provider)\n[![Coverage Status](https://coveralls.io/repos/github/hlhr202/React-Combine-Provider/badge.svg?branch=master)](https://coveralls.io/github/hlhr202/React-Combine-Provider?branch=master)\n[![CircleCI](https://circleci.com/gh/hlhr202/React-Combine-Provider.svg?style=shield)](https://circleci.com/gh/hlhr202/React-Combine-Provider)\n![TypeDefine](https://img.shields.io/npm/types/chalk.svg)\n[![License](https://img.shields.io/npm/l/react-combine-provider.svg)](https://github.com/hlhr202/React-Combine-Provider/blob/master/LICENSE)\n\nCombine react providers in ease  \nRequires React \u003e= 16.8.0  \nFully support [unstated-next](https://github.com/jamiebuilds/unstated-next) and [constate](https://github.com/diegohaz/constate)  \n\n## Install\n\n```\nnpm install --save react-combine-provider\n```\n\n## Usage\n\n- unstated\n\n```jsx\nimport React, { useState } from 'react';\nimport ReactDOM from 'react-dom';\nimport { createContainer } from 'unstated-next';\nimport { combineProviders } from 'react-combine-provider';\n\nconst useCounter1 = (initialState = 1) =\u003e {\n    const [count, setCount] = useState(initialState);\n    const decrement = () =\u003e setCount(count - 1);\n    const increment = () =\u003e setCount(count + 1);\n    return { count, decrement, increment };\n};\n\nconst Counter1 = createContainer(useCounter1);\n\nconst useCounter2 = (initialState = 2) =\u003e {\n  const [count, setCount] = useState(initialState);\n  const decrement = () =\u003e setCount(count - 2);\n  const increment = () =\u003e setCount(count + 2);\n  return { count, decrement, increment };\n};\n\nconst Counter2 = createContainer(useCounter2);\n\nfunction CounterDisplay1() {\n  const counter1 = Counter1.useContainer();\n  console.log('rendering');\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003ecounter display 1\u003c/div\u003e\n      \u003cdiv\u003ecounter 1\u003c/div\u003e\n      \u003cbutton onClick={counter1.decrement}\u003e-\u003c/button\u003e\n      \u003cspan\u003e{counter1.count}\u003c/span\u003e\n      \u003cbutton onClick={counter1.increment}\u003e+\u003c/button\u003e\n      \u003cbr /\u003e\n    \u003c/div\u003e\n  );\n}\n\nfunction CounterDisplay2() {\n  const counter1 = Counter1.useContainer();\n  const counter2 = Counter2.useContainer();\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003ecounter display 2\u003c/div\u003e\n      \u003cdiv\u003ecounter 1\u003c/div\u003e\n      \u003cbutton onClick={counter1.decrement}\u003e-\u003c/button\u003e\n      \u003cspan\u003e{counter1.count}\u003c/span\u003e\n      \u003cbutton onClick={counter1.increment}\u003e+\u003c/button\u003e\n      \u003cdiv\u003ecounter 2\u003c/div\u003e\n      \u003cbutton onClick={counter2.decrement}\u003e-\u003c/button\u003e\n      \u003cspan\u003e{counter2.count}\u003c/span\u003e\n      \u003cbutton onClick={counter2.increment}\u003e+\u003c/button\u003e\n      \u003cbr /\u003e\n    \u003c/div\u003e\n  );\n}\n\nconst StateProviders = combineProviders([\n  [Counter1.Provider, { initialState: 5 }],\n  Counter2.Provider,\n]);\n\nfunction App() {\n  return (\n    \u003cStateProviders\u003e\n      \u003cCounterDisplay1 /\u003e\n      \u003cbr /\u003e\n      \u003cCounterDisplay2 /\u003e\n    \u003c/StateProviders\u003e\n  );\n}\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById('root'));\n```\n\n## TODO\n  - [] reference of hooks in another hooks\n  - [] dynamic hooks injection","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlhr202%2FReact-Combine-Provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlhr202%2FReact-Combine-Provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlhr202%2FReact-Combine-Provider/lists"}