{"id":9884424,"url":"https://github.com/flaviouk/react-redux-local","last_synced_at":"2025-08-29T08:31:39.539Z","repository":{"id":57343282,"uuid":"112882745","full_name":"flaviouk/react-redux-local","owner":"flaviouk","description":"Small, yet powerful version of react-redux, out of the box support for the new context api and any middleware","archived":false,"fork":false,"pushed_at":"2022-08-16T20:52:22.000Z","size":794,"stargazers_count":22,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-21T02:57:37.030Z","etag":null,"topics":[],"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/flaviouk.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":"2017-12-02T22:43:32.000Z","updated_at":"2024-08-07T10:21:35.000Z","dependencies_parsed_at":"2022-09-12T07:00:18.950Z","dependency_job_id":null,"html_url":"https://github.com/flaviouk/react-redux-local","commit_stats":null,"previous_names":["imflavio/react-redux-local","codebyflavio/react-redux-local","realflavioc/react-redux-local","flaviouk/react-redux-local"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviouk%2Freact-redux-local","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviouk%2Freact-redux-local/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviouk%2Freact-redux-local/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviouk%2Freact-redux-local/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flaviouk","download_url":"https://codeload.github.com/flaviouk/react-redux-local/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231351033,"owners_count":18363436,"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":[],"created_at":"2024-05-18T18:20:45.151Z","updated_at":"2024-12-26T11:30:31.767Z","avatar_url":"https://github.com/flaviouk.png","language":"JavaScript","funding_links":[],"categories":["Components"],"sub_categories":["Data"],"readme":"# react-redux-local\n\n[![Build Status][build-badge]][build]\n[![Code Coverage][coverage-badge]][coverage]\n[![version][version-badge]][package]\n[![downloads][downloads-badge]][npmtrends]\n\n[![PRs Welcome][prs-badge]][prs]\n[![MIT License][license-badge]][license]\n\n[![Watch on GitHub][github-watch-badge]][github-watch]\n[![Star on GitHub][github-star-badge]][github-star]\n[![Tweet][twitter-badge]][twitter]\n\n# The problem\n\nI love redux, but building a small and simple local reducer component on every project is not on top of the list of things I like to do the most, plus what if I want to take advantage of sagas, dev tools and the new context api? It becomes a not so simple component very quickly.\n\n# The solution\n\nYou can think of `react-redux-local` as a mini, yet powerful version of [react-redux](https://github.com/reactjs/redux), the api is very simple, abstracting away things like creating a redux store, adding middleware, binding actions and plugging in the redux dev tools.\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Api](#api)\n- [Examples](#examples)\n- [Other Solutions](#other-solutions)\n- [LICENSE](#license)\n\n# Installation\n\nThis module is distributed via [npm][npm] which is bundled with [node][node] and\nshould be installed as one of your project's `dependencies`:\n\n```\nyarn add react-redux-local\n```\n\n# Usage\n\n## LocalReducer\n\n```jsx\nimport LocalReducer from 'react-redux-local'\n\n// https://github.com/erikras/ducks-modular-redux\nimport { actions, reducer, saga, middleware, devToolsOptions } from './duck'\n\nconst App = () =\u003e (\n  \u003cLocalReducer\n    actions={actions}\n    reducer={reducer}\n    saga={saga}\n    middleware={middleware}\n    devToolsOptions={devToolsOptions}\n  \u003e\n    {(state, actions, dispatch) =\u003e (\n      \u003cYourComponent state={state} actions={actions} /\u003e\n    )}\n  \u003c/LocalReducer\u003e\n)\n```\n\n## createContext\n\n```jsx\nimport { createContext } from 'react-redux-local'\n\nimport { actions, reducer, saga, middleware, devToolsOptions } from './redux'\n\nconst { Provider, Consumer } = createContext({\n  actions,\n  reducer,\n  saga,\n  middleware,\n  devToolsOptions,\n})\n\nconst Up = () =\u003e (\n  \u003cConsumer mapActions={({ countUp }) =\u003e countUp}\u003e\n    {(_, action) =\u003e \u003cbutton onClick={action}\u003eUP\u003c/button\u003e}\n  \u003c/Consumer\u003e\n)\n\nconst Down = () =\u003e (\n  \u003cConsumer mapActions={({ countDown }) =\u003e countDown}\u003e\n    {(_, action) =\u003e \u003cbutton onClick={action}\u003eDOWN\u003c/button\u003e}\n  \u003c/Consumer\u003e\n)\n\n// Will only rerender when the \"counter\" state changes\nconst Count = () =\u003e (\n  \u003cConsumer mapState={({ counter }) =\u003e counter}\u003e\n    {state =\u003e \u003ch3\u003eCount: {state}\u003c/h3\u003e}\n  \u003c/Consumer\u003e\n)\n\n// Will only rerender when the \"total\" state changes\nconst TotalCount = () =\u003e (\n  \u003cConsumer mapState={({ total }) =\u003e total}\u003e\n    {state =\u003e \u003ch3\u003eTotal count: {state}\u003c/h3\u003e}\n  \u003c/Consumer\u003e\n)\n\n// Will only rerender when the \"downs\" state changes\nconst DownsOnly = () =\u003e (\n  \u003cConsumer mapState={({ downs }) =\u003e downs}\u003e\n    {state =\u003e \u003ch3\u003eDowns: {state}\u003c/h3\u003e}\n  \u003c/Consumer\u003e\n)\n\nconst App = () =\u003e (\n  \u003cProvider\u003e\n    \u003cUp /\u003e\n\n    \u003cDown /\u003e\n\n    \u003cCount /\u003e\n\n    \u003cTotalCount /\u003e\n\n    \u003cDownOnly /\u003e\n  \u003c/Provider\u003e\n)\n```\n\n# Api\n\n## Props\n\n\u003e Tip: `createContext` takes the same props as `LocalReducer`\n\n### `reducer`\n\n\u003e func.isRequired\n\nA reducer specifies how the application's state changes in response to actions sent to the store.\n\n[Learn More](https://redux.js.org/basics/reducers)\n\n\u003e e.g.\n\n```jsx\nconst initialState = { counter: 0, total: 0, downs: 0 }\nconst reducer = (state = initialState, action) =\u003e {\n  switch (action.type) {\n    case 'COUNT_UP':\n      return {\n        counter: state.counter + 1,\n        total: state.total + 1,\n        downs: state.downs,\n      }\n\n    case 'COUNT_DOWN':\n      return {\n        counter: state.counter - 1,\n        total: state.total + 1,\n        downs: state.downs + 1,\n      }\n\n    default:\n      return state\n  }\n}\n```\n\n### `actions`\n\n\u003e objectOf(func.isRequired).isRequired\n\nActions are payloads of information that send data from your application to your store. They are the only source of information for the store.\n\n[Learn More](https://redux.js.org/basics/actions)\n\n\u003e e.g.\n\n```jsx\nconst actions = {\n  countUp: () =\u003e ({ type: 'COUNT_UP' }),\n  countDown: () =\u003e ({ type: 'COUNT_DOWN' }),\n}\n```\n\n### `saga`\n\n\u003e func\n\nAims to make application side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache) easier to manage, more efficient to execute, simple to test, and better at handling failures.\n\n[Learn More](https://github.com/redux-saga/redux-saga)\n\n\u003e e.g.\n\n```jsx\nimport { put } from 'redux-saga'\n\nfunction* doubleCount() {\n  put(actions.countUp())\n}\n\nfunction* saga() {\n  yield takeEvery('COUNT_UP', doubleCount)\n}\n```\n\n### `middleware`\n\n\u003e arrayOf(func.isRequired)\n\nIt provides a third-party extension point between dispatching an action, and the moment it reaches the reducer.\n\n[Learn More](https://redux.js.org/advanced/middleware)\n\n```jsx\nconst middleware = store =\u003e next =\u003e action =\u003e {\n  console.log(action.type)\n  return next(action)\n}\n```\n\n### `devToolsOptions`\n\n\u003e object\n\nAllows for a better development experience with redux.\n\n[Dev Tools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en)\n\n[Learn More](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#windowdevtoolsextensionconfig)\n\n\u003e e.g.\n\n```jsx\nconst devToolsOptions = { name: 'My own devtools tab' }\n```\n\n### `children`\n\n\u003e func.isRequired\n\nThe term “render prop” refers to a simple technique for sharing code between React components using a prop whose value is a function.\n\n[Learn More](https://reactjs.org/docs/render-props.html)\n\n\u003e Video: Michael Jackson - Never Write Another HoC\n\n[![Michael Jackson - Never Write Another HoC](https://img.youtube.com/vi/BcVAq3YFiuc/0.jpg)](https://www.youtube.com/watch?v=BcVAq3YFiuc)\n\n## `\u003cConsumer /\u003e` props (from `createContext`)\n\n### `mapState`\n\n\u003e func | state =\u003e undefined\n\nBehaves like `mapStateToProps` from `react-redux` with the exception that it won't be available in the props (duh) and you are not required to return an object (thank you render props)\n\n### `mapActions`\n\n\u003e func | (actions, dispatch) =\u003e undefined\n\nAllows you to pick what actions you want available in the second argument of your render function. `dispatch` is very much optional since all the actions are binded automatically.\n\n## `\u003cLocalReducer /\u003e` render function\n\n```jsx\n;(state, actions, dispatch) =\u003e \u003cYourComponent /\u003e\n```\n\n### `state`\n\nYour application state.\n\n### `actions`\n\nBinded actions. (You don't need to dispatch)\n\n### `dispatch`\n\n\u003cb\u003eOptional\u003c/b\u003e function that allows you to dispatch other actions.\n\n```jsx\ndispatch({ type: 'VERY_CUSTOM_ACTION' })\n```\n\n# Examples\n\n- [counter-example](https://codesandbox.io/s/oj14r3qvn6?module=%2Fsrc%2Fcontext.js)\n\n# Other Solutions\n\n[local-react-redux](https://github.com/HansDP/local-react-redux)\n\n[local-react-redux-saga](https://github.com/HansDP/local-react-redux-saga)\n\n[react-local-reducer](https://github.com/troch/react-local-reducer)\n\n[react-copy-write](https://github.com/aweary/react-copy-write)\n\n# LICENSE\n\nMIT\n\n[npm]: https://www.npmjs.com/\n[node]: https://nodejs.org\n[build-badge]: https://img.shields.io/travis/imflavio/react-redux-local.svg?style=flat-square\n[build]: https://travis-ci.org/imflavio/react-redux-local\n[coverage-badge]: https://img.shields.io/codecov/c/github/imflavio/react-redux-local.svg?style=flat-square\n[coverage]: https://codecov.io/github/imflavio/react-redux-local\n[version-badge]: https://img.shields.io/npm/v/react-redux-local.svg?style=flat-square\n[package]: https://www.npmjs.com/package/react-redux-local\n[downloads-badge]: https://img.shields.io/npm/dm/react-redux-local.svg?style=flat-square\n[npmtrends]: http://www.npmtrends.com/react-redux-local\n[license-badge]: https://img.shields.io/npm/l/react-redux-local.svg?style=flat-square\n[license]: https://github.com/imflavio/react-redux-local/blob/master/LICENSE\n[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square\n[prs]: http://makeapullrequest.com\n[donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square\n[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square\n[coc]: https://github.com/imflavio/react-redux-local/blob/master/other/CODE_OF_CONDUCT.md\n[github-watch-badge]: https://img.shields.io/github/watchers/imflavio/react-redux-local.svg?style=social\n[github-watch]: https://github.com/imflavio/react-redux-local/watchers\n[github-star-badge]: https://img.shields.io/github/stars/imflavio/react-redux-local.svg?style=social\n[github-star]: https://github.com/imflavio/react-redux-local/stargazers\n[twitter]: https://twitter.com/intent/tweet?text=Check%20out%20react-redux-local%20by%20%40imflavio_%20https%3A%2F%2Fgithub.com%2Fimflavio%2Freact-redux-local%20%F0%9F%91%8D\n[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/imflavio/react-redux-local.svg?style=social\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaviouk%2Freact-redux-local","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflaviouk%2Freact-redux-local","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaviouk%2Freact-redux-local/lists"}