{"id":13451998,"url":"https://github.com/RisingStack/react-easy-state","last_synced_at":"2025-03-23T19:33:27.631Z","repository":{"id":38173274,"uuid":"92187939","full_name":"RisingStack/react-easy-state","owner":"RisingStack","description":"Simple React state management. Made with ❤️ and ES6 Proxies.","archived":false,"fork":false,"pushed_at":"2023-01-06T21:00:43.000Z","size":18318,"stargazers_count":2558,"open_issues_count":199,"forks_count":103,"subscribers_count":42,"default_branch":"master","last_synced_at":"2024-10-29T15:04:05.588Z","etag":null,"topics":["es6-proxies","javascript","react","react-state","reactive-programming","reactjs","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/RisingStack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-23T15:17:43.000Z","updated_at":"2024-10-27T23:01:36.000Z","dependencies_parsed_at":"2023-02-06T09:16:18.016Z","dependency_job_id":null,"html_url":"https://github.com/RisingStack/react-easy-state","commit_stats":null,"previous_names":["solkimicreb/react-easy-state"],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Freact-easy-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Freact-easy-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Freact-easy-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Freact-easy-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RisingStack","download_url":"https://codeload.github.com/RisingStack/react-easy-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245158891,"owners_count":20570281,"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":["es6-proxies","javascript","react","react-state","reactive-programming","reactjs","state","state-management"],"created_at":"2024-07-31T07:01:09.627Z","updated_at":"2025-03-23T19:33:26.575Z","avatar_url":"https://github.com/RisingStack.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/logo.svg\" width=\"600px\" height=\"auto\" /\u003e\n\u003c/p\u003e\n\n## React Easy State - by [RisingStack](https://risingstack.com/)\n\n[![Build](https://img.shields.io/circleci/project/github/RisingStack/react-easy-state/master.svg)](https://circleci.com/gh/RisingStack/react-easy-state/tree/master) [![dependencies Status](https://david-dm.org/RisingStack/react-easy-state/status.svg)](https://david-dm.org/RisingStack/react-easy-state) [![Coverage Status](https://coveralls.io/repos/github/RisingStack/react-easy-state/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/RisingStack/react-easy-state?branch=master) [![Package size](https://img.shields.io/bundlephobia/minzip/@risingstack/react-easy-state.svg)](https://bundlephobia.com/result?p=@risingstack/react-easy-state) [![Version](https://img.shields.io/npm/v/@risingstack/react-easy-state.svg)](https://www.npmjs.com/package/@risingstack/react-easy-state) [![License](https://img.shields.io/npm/l/@risingstack/react-easy-state.svg)](https://www.npmjs.com/package/@risingstack/react-easy-state) \u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-4-blue.svg)](#contributors)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\n\u003ca href=\"#platform-support-computer\"\u003e\u003cimg src=\"images/browser_support.png\" alt=\"Browser support\" width=\"450px\" height=\"auto\" /\u003e\u003c/a\u003e\n\n**NEWS:** v6.3.0 fixed a nasty bug that could render [zombie children](https://react-redux.js.org/api/hooks#stale-props-and-zombie-children). Please update to this version at least to save yourself some headaches. Thanks!\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eTable of Contents\u003c/strong\u003e\u003c/summary\u003e\n\u003c!-- Do not edit the Table of Contents, instead regenerate with `npm run build-toc` --\u003e\n\n\u003c!-- toc --\u003e\n\n* [Introduction :wave:](#introduction-wave)\n* [Installation :cd:](#installation-cd)\n* [Everyday Usage :sunglasses:](#everyday-usage-sunglasses)\n  + [Creating global stores](#creating-global-stores)\n  + [Creating reactive views](#creating-reactive-views)\n  + [Creating local stores](#creating-local-stores)\n* [Advanced Usage :nerd_face:](#advanced-usage-nerd_face)\n  + [Adding side effects](#adding-side-effects)\n* [API Summary :book:](#api-summary-book)\n  + [store(obj)](#storeobj)\n  + [view(Comp)](#viewcomp)\n  + [batch(fn)](#batchfn)\n  + [autoEffect(fn)](#autoeffectfn)\n  + [clearEffect(fn)](#cleareffectfn)\n* [Examples with live demos :tv:](#examples-with-live-demos-tv)\n* [Articles :loudspeaker:](#articles-loudspeaker)\n* [Performance :rocket:](#performance-rocket)\n* [Platform support :computer:](#platform-support-computer)\n* [Alternative builds :wrench:](#alternative-builds-wrench)\n* [Contributors :sparkles:](#contributors-sparkles)\n\n\u003c!-- tocstop --\u003e\n\n\u003c/details\u003e\n\n## Introduction :wave:\n\nReact Easy State is a practical state management library with two functions and two accompanying rules.\n\n1.  Always wrap your components with `view()`.\n2.  Always wrap your state store objects with `store()`.\n\n```jsx\nimport React from 'react';\nimport { store, view } from '@risingstack/react-easy-state';\n\nconst counter = store({\n  num: 0,\n  increment: () =\u003e counter.num++\n});\n\nexport default view(() =\u003e (\n  \u003cbutton onClick={counter.increment}\u003e{counter.num}\u003c/button\u003e\n));\n```\n\nThis is enough for it to automatically update your views when needed. It doesn't matter how you structure or mutate your state stores, any syntactically valid code works.\n\nCheck this [TodoMVC codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/todo-mvc?module=%2Fsrc%2FtodosStore.js) or [raw code](/examples/todo-mvc/src/todosStore.js) for a more exciting example with nested data, arrays and getter properties.\n\n## Installation :cd:\n\n`npm install @risingstack/react-easy-state`\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eSetting up a quick project\u003c/strong\u003e\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\nEasy State supports \u003ca href=\"https://github.com/facebookincubator/create-react-app\"\u003eCreate React App\u003c/a\u003e without additional configuration. Just run the following commands to get started.\n\n```sh\nnpx create-react-app my-app\ncd my-app\nnpm install @risingstack/react-easy-state\nnpm start\n```\n\n_You need npm 5.2+ to use npx._\n\n\u003c/details\u003e\n\n## Everyday Usage :sunglasses:\n\n### Creating global stores\n\n`store` creates a state store from the passed object and returns it. A state store behaves just like the passed object. (To be precise, it is a transparent reactive proxy of the original object.)\n\n```js\nimport { store } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Rick' });\n// stores behave like normal JS objects\nuser.name = 'Bob';\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eState stores may have arbitrary structure and they may be mutated in any syntactically valid way.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```js\nimport { store } from '@risingstack/react-easy-state';\n\n// stores can include any valid JS structure\n// including nested data, arrays, Maps, Sets, getters, setters, inheritance, ...\nconst user = store({\n  profile: {\n    firstName: 'Bob',\n    lastName: 'Smith',\n    get name() {\n      return `${user.profile.firstName} ${user.profile.lastName}`;\n    },\n  },\n  hobbies: ['programming', 'sports'],\n  friends: new Map(),\n});\n\n// stores may be mutated in any syntactically valid way\nuser.profile.firstName = 'Bob';\ndelete user.profile.lastName;\nuser.hobbies.push('reading');\nuser.friends.set('id', otherUser);\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAsync operations can be expressed with the standard async/await syntax.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```js\nimport { store } from '@risingstack/react-easy-state';\n\nconst userStore = store({\n  user: {},\n  async fetchUser() {\n    userStore.user = await fetch('/user');\n  },\n});\n\nexport default userStore;\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eState stores may import and use other state stores in their methods.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n_userStore.js_\n\n```js\nimport { store } from '@risingstack/react-easy-state';\n\nconst userStore = store({\n  user: {},\n  async fetchUser() {\n    userStore.user = await fetch('/user');\n  },\n});\n\nexport default userStore;\n```\n\n_recipesStore.js_\n\n```js\nimport { store } from '@risingstack/react-easy-state';\nimport userStore from './userStore';\n\nconst recipesStore = store({\n  recipes: [],\n  async fetchRecipes() {\n    recipesStore.recipes = await fetch(\n      `/recipes?user=${userStore.user.id}`,\n    );\n  },\n});\n\nexport default recipesStore;\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWrap your state stores with \u003ccode\u003estore\u003c/code\u003e as early as possible.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```js\n// DON'T DO THIS\nconst person = { name: 'Bob' };\nperson.name = 'Ann';\n\nexport default store(person);\n```\n\n```js\n// DO THIS INSTEAD\nconst person = store({ name: 'Bob' });\nperson.name = 'Ann';\n\nexport default person;\n```\n\nThe first example wouldn't trigger re-renders on the `person.name = 'Ann'` mutation, because it is targeted at the raw object. Mutating the raw - none `store`-wrapped object - won't schedule renders.\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAvoid using the \u003ccode\u003ethis\u003c/code\u003e keyword in the methods of your state stores.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport { store, view } from '@risingstack/react-easy-state';\n\nconst counter = store({\n  num: 0,\n  increment() {\n    // DON'T DO THIS\n    this.num++;\n    // DO THIS INSTEAD\n    counter.num++;\n  },\n});\n\nexport default view(() =\u003e (\n  \u003cdiv onClick={counter.increment}\u003e{counter.num}\u003c/div\u003e\n));\n```\n\n`this.num++` won't work, because `increment` is passed as a callback and loses its `this`. You should use the direct object reference - `counter` - instead of `this`.\n\n\u003c/details\u003e\n\n### Creating reactive views\n\nWrapping your components with `view` turns them into reactive views. A reactive view re-renders whenever a piece of store - used inside its render - changes.\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\n// this is a global state store\nconst user = store({ name: 'Bob' });\n\n// this is re-rendered whenever user.name changes\nexport default view(() =\u003e (\n  \u003cdiv\u003e\n    \u003cinput\n      value={user.name}\n      onChange={ev =\u003e (user.name = ev.target.value)}\n    /\u003e\n    \u003cdiv\u003eHello {user.name}!\u003c/div\u003e\n  \u003c/div\u003e\n));\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eWrap ALL of your components with \u003ccode\u003eview\u003c/code\u003e - including class and function ones - even if they don't seem to directly use a store.\u003c/strong\u003e\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\nEvery component that is using a store or part of a store inside its render must be wrapped with `view`. Sometimes store usage is not so explicit and easy to to miss.\n\n```jsx\nimport { view, store } from '@risingstack/react-easy-state';\n\nconst appStore = store({\n  user: { name: 'Ann' },\n});\n\nconst App = view(() =\u003e (\n  \u003cdiv\u003e\n    \u003ch1\u003eMy App\u003c/h1\u003e\n    \u003cProfile user={appStore.user} /\u003e\n  \u003c/div\u003e\n));\n\n// DO THIS\nconst Profile = view(({ user }) =\u003e \u003cp\u003eName: {user.name}\u003c/p\u003e);\n\n// DON'T DO THIS\n// This won't re-render on appStore.user.name = 'newName' like mutations\nconst Profile = ({ user }) =\u003e \u003cp\u003eName: {user.name}\u003c/p\u003e;\n```\n\nIf you are **100% sure** that your component is not using any stores you can skip the `view` wrapper.\n\n```jsx\nimport React from 'react';\n\n// you don't have to wrap this component with `view`\nexport default (() =\u003e \u003cp\u003eThis is just plain text\u003c/p\u003e);\n```\n\n`view` wrapping is advised even in these cases though.\n\n- It saves you from future headaches as your project grows and you start to use stores inside these components.\n- `view` is pretty much equivalent to `memo` if you don't use any stores. That is nearly always nice to have.\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eA single reactive component may use multiple stores inside its render.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob' });\nconst timeline = store({ posts: ['react-easy-state'] });\n\n// this is re-rendered whenever user.name or timeline.posts[0] changes\nexport default view(() =\u003e (\n  \u003cdiv\u003e\n    \u003cdiv\u003eHello {user.name}!\u003c/div\u003e\n    \u003cdiv\u003eYour first post is: {timeline.posts[0]}\u003c/div\u003e\n  \u003c/div\u003e\n));\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eview\u003c/code\u003e implements an optimal \u003ccode\u003eshouldComponentUpdate\u003c/code\u003e (or \u003ccode\u003ememo\u003c/code\u003e) for your components.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n- Using `PureComponent` or `memo` will provide no additional performance benefits.\n\n- Defining a custom `shouldComponentUpdate` may rarely provide performance benefits when you apply some use case specific heuristics inside it.\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eReactive renders are batched. Multiple synchronous store mutations won't result in multiple re-renders of the same component.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob', age: 30 });\n\nfunction mutateUser() {\n  user.name = 'Ann';\n  user.age = 32;\n}\n\n// calling `mutateUser` will only trigger a single re-render of the below component\n// even though it mutates the store two times in quick succession\nexport default view(() =\u003e (\n  \u003cdiv onClick={mutateUser}\u003e\n    name: {user.name}, age: {user.age}\n  \u003c/div\u003e\n));\n```\n\nIf you mutate your stores multiple times synchronously from **exotic task sources**, multiple renders may rarely happen. If you experience performance issues you can batch changes manually with the `batch` function. `batch(fn)` executes the passed function immediately and batches any subsequent re-renders until the function execution finishes.\n\n```jsx\nimport React from 'react';\nimport { view, store, batch } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob', age: 30 });\n\nfunction mutateUser() {\n  // this makes sure the state changes will cause maximum one re-render,\n  // no matter where this function is getting invoked from\n  batch(() =\u003e {\n    user.name = 'Ann';\n    user.age = 32;\n  });\n}\n\nexport default view(() =\u003e (\n  \u003cdiv\u003e\n    name: {user.name}, age: {user.age}\n  \u003c/div\u003e\n));\n```\n\n\u003e **NOTE:** The React team plans to improve render batching in the future. The `batch` function and built-in batching may be deprecated and removed in the future in favor of React's own batching.\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAlways apply \u003ccode\u003eview\u003c/code\u003e as the latest (innermost) wrapper when you combine it with other Higher Order Components.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport { view } from '@risingstack/react-easy-state';\nimport { withRouter } from 'react-router-dom';\nimport { withTheme } from 'styled-components';\n\nconst Comp = () =\u003e \u003cdiv\u003eA reactive component\u003c/div\u003e;\n\n// DO THIS\nwithRouter(view(Comp));\nwithTheme(view(Comp));\n\n// DON'T DO THIS\nview(withRouter(Comp));\nview(withTheme(Comp));\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eUsage with (pre v4.4) React Router.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n- If routing is not updated properly, wrap your `view(Comp)` - with the `Route`s inside - in `withRouter(view(Comp))`. This lets react-router know when to update.\n\n- The order of the HOCs matter, always use `withRouter(view(Comp))`.\n\nThis is not necessary if you use React Router 4.4+. You can find more details and some reasoning about this in [this react-router docs page](https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/blocked-updates.md).\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eUsage with React Developer Tools.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\nIf you want React Developer Tools to recognize your reactive view components' names, you have to pass either a **named function** or an anonymous function with **name inference** to the `view` wrapper.\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nconst user = store({\n  name: 'Rick',\n});\n\nconst componentName = () =\u003e (\n  \u003cdiv\u003e{user.name}\u003c/div\u003e\n);\n\nexport default view(componentName);\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePassing nested data to third party components.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\nThird party helpers - like data grids - may consist of many internal components which can not be wrapped by `view`, but sometimes you would like them to re-render when the passed data mutates. Traditional React components re-render when their props change by reference, so mutating the passed reactive data won't work in these cases. You can solve this issue by deep cloning the observable data before passing it to the component. This creates a new reference for the consuming component on every store mutation.\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\nimport Table from 'rc-table';\nimport cloneDeep from 'lodash/cloneDeep';\n\nconst dataStore = store({\n  items: [\n    {\n      product: 'Car',\n      value: 12,\n    },\n  ],\n});\n\nexport default view(() =\u003e (\n  \u003cTable data={cloneDeep(dataStore.items)} /\u003e\n));\n```\n\n\u003c/details\u003e\n\n### Creating local stores\n\nA singleton global store is perfect for something like the current user, but sometimes having local component states is a better fit. Just create a store inside a function component or as a class component property in these cases.\n\n#### Local stores in function components\n\n```jsx\nimport React from 'react'\nimport { view, store } from '@risingstack/react-easy-state'\n\nexport default view(() =\u003e {\n  const counter = store({ num: 0 })\n  const increment = () =\u003e counter.num++\n  return \u003cbutton={increment}\u003e{counter.num}\u003c/button\u003e\n})\n```\n\n**Local stores in functions rely on React hooks. They require React and React DOM v16.8+ or React Native v0.59+ to work.**\n\n\u003cdetails\u003e\n\u003csummary\u003eYou can use React hooks - including \u003ccode\u003euseState\u003c/code\u003e - in function components, Easy State won't interfere with them. Consider using \u003ca href=\"#local-auto-effects-in-function-components\"\u003eautoEffect\u003c/a\u003e instead of the \u003ccode\u003euseEffect\u003c/code\u003e hook for the best experience though.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nexport default view(() =\u003e {\n  const [name, setName] = useState('Ann');\n  const user = store({ age: 30 });\n  return (\n    \u003cdiv\u003e\n      \u003cinput value={name} onChange={ev =\u003e setName(ev.target.value)} /\u003e\n      \u003cinput\n        value={user.age}\n        onChange={ev =\u003e (user.age = ev.target.value)}\n      /\u003e\n    \u003c/div\u003e\n  );\n});\n```\n\n\u003c/details\u003e\n\n#### Local stores in class components\n\n```jsx\nimport React, { Component } from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nclass Counter extends Component {\n  counter = store({ num: 0 });\n  increment = () =\u003e counter.num++;\n\n  render() {\n    return (\n      \u003cbutton onClick={this.increment}\u003e{this.counter.num}\u003c/button\u003e\n    );\n  }\n}\n\nexport default view(Counter);\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eYou can also use vanilla \u003ccode\u003esetState\u003c/code\u003e in your class components, Easy State won't interfere with it.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport React, { Component } from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nclass Profile extends Component {\n  state = { name: 'Ann' };\n  user = store({ age: 30 });\n\n  setName = ev =\u003e this.setState({ name: ev.target.value });\n  setAge = ev =\u003e (this.user.age = ev.target.value);\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cinput value={this.state.name} onChange={this.setName} /\u003e\n        \u003cinput value={this.user.age} onChange={this.setAge} /\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\nexport default view(Profile);\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eDon't name local stores as \u003ccode\u003estate\u003c/code\u003e. It may conflict with linter rules, which guard against direct state mutations.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport React, { Component } from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nclass Profile extends Component {\n  // DON'T DO THIS\n  state = store({});\n  // DO THIS\n  user = store({});\n  render() {}\n}\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eDeriving local stores from props (\u003ccode\u003egetDerivedStateFromProps\u003c/code\u003e).\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\nClass components wrapped with `view` have an extra static `deriveStoresFromProps` lifecycle method, which works similarly to the vanilla `getDerivedStateFromProps`.\n\n```jsx\nimport React, { Component } from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nclass NameCard extends Component {\n  userStore = store({ name: 'Bob' });\n\n  static deriveStoresFromProps(props, userStore) {\n    userStore.name = props.name || userStore.name;\n  }\n\n  render() {\n    return \u003cdiv\u003e{this.userStore.name}\u003c/div\u003e;\n  }\n}\n\nexport default view(NameCard);\n```\n\nInstead of returning an object, you should directly mutate the received stores. If you have multiple local stores on a single component, they are all passed as arguments - in their definition order - after the first props argument.\n\n\u003c/details\u003e\n\n## Advanced Usage :nerd_face:\n\n### Adding side effects\n\nUse `autoEffect` to react with automatic side effect to your store changes. Auto effects should contain end-of-chain logic - like changing the document title or saving data to LocalStorage. `view` is a special auto effect that does rendering.\n\n\u003cdetails\u003e\n\u003csummary\u003eNever use auto effects to derive data from other data. Use dynamic getters instead.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\n```jsx\nimport { store, autoEffect } from '@risingstack/react-easy-state';\n\n// DON'T DO THIS\nconst store1 = store({ name: 'Store 1' })\nconst store2 = store({ name: 'Store 2' })\nautoEffect(() =\u003e store2.name = store1.name)\n\n// DO THIS INSTEAD\nconst store1 = store({ name: 'Store 1' })\nconst store2 = store({ get name () { return store1.name } })\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n#### Global auto effects\n\nGlobal auto effects can be created with `autoEffect` and cleared up with `clearEffect`.\n\n```jsx\nimport { store, autoEffect, clearEffect } from '@risingstack/react-easy-state';\n\nconst app = store({ name: 'My App' })\nconst effect = autoEffect(() =\u003e document.title = app.name)\n\n// this also updates the document title\napp.name = 'My Awesome App'\n\nclearEffect(effect)\n// this won't update the document title, the effect is cleared\napp.name = 'My App'\n```\n\n#### Local auto effects in function components\n\nUse local auto effects in function components instead of the `useEffect` hook when reactive stores are used inside them. These local effects are automatically cleared when the component unmounts.\n\n```jsx\nimport React from 'react'\nimport { store, view, autoEffect } from '@risingstack/react-easy-state';\n\nexport default view(() =\u003e {\n  const app = store({ name: 'My App' })\n  // no need to clear the effect\n  autoEffect(() =\u003e document.title = app.name)\n})\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eExplicitly pass none reactive dependencies - like vanillas props and state - to local auto effects in function components.\u003c/summary\u003e\n\u003cp\u003e\u003c/p\u003e\n\nBecause of the design of React hooks you have to explicitly pass all none reactive data to a hook-like dependency array. This makes sure that the effect also runs when the none reactive data changes.\n\n```jsx\nimport React from 'react'\nimport { store, view, autoEffect } from '@risingstack/react-easy-state';\n\nexport default view(({ greeting }) =\u003e {\n  const app = store({ name: 'My App' })\n  // pass `greeting` in the dependency array because it is not coming from a store\n  autoEffect(() =\u003e document.title = `${greeting} ${app.name}`, [greeting])\n})\n```\n\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n#### Local auto effects in class components\n\nLocal effects in class components must be cleared when the component unmounts.\n\n```jsx\nimport React, { Component } from 'react'\nimport { store, view, autoEffect } from '@risingstack/react-easy-state';\n\nclass App extends Component {\n  app = store({ name: 'My App' })\n\n  componentDidMount () {\n    this.effect = autoEffect(() =\u003e document.title = this.app.name)\n  }\n\n  componentWillUnmount () {\n    // local effects in class components must be cleared on unmount\n    clearEffect(this.effect)\n  }\n}\n```\n\n## API Summary :book:\n\n### store(obj)\n\nCreates an observable store from the passed object and returns it. Can be used outside components for [global stores](#creating-global-stores) and inside components for [local stores]((#creating-local-stores)).\n\n```js\nimport { store } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Rick' });\n```\n\n### view(Comp)\n\nCreates a [reactive view](#creating-reactive-views) from the passed component and returns it. A reactive view re-renders whenever any store data used inside it is mutated.\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob' });\n\nexport default view(() =\u003e (\n  \u003cdiv\u003eHello {user.name}!\u003c/div\u003e\n));\n```\n\n### batch(fn)\n\nImmediately executes the passed function and batches all store mutations inside it. Batched mutations are guaranteed to not trigger unnecessary double renders. Most task sources are batched automatically, only  use `batch` if you encounter performance issues.\n\n```jsx\nimport React from 'react';\nimport { view, store } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob' });\n\nfunction setName() {\n  batch(() =\u003e {\n    user.name = 'Rick'\n    user.name = 'Ann'\n  })\n}\n```\n\n### autoEffect(fn)\n\nCreates a reactive function from the passed one, immediately executes it, and returns it. A reactive function automatically re-reruns whenever any store data used inside it is mutated.\n\nCan be used both [outside](#global-auto-effects) and [inside](#local-auto-effects-in-function-components) components.\n\n```js\nimport { store, autoEffect } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob' })\n\nautoEffect(() =\u003e document.title = user.name)\n```\n\n### clearEffect(fn)\n\nTakes a reactive function (returned by `autoEffect`) and clears the reactivity from it. Cleared reactive functions will no longer re-rerun on related store mutations. Reactive functions created inside function components are automatically cleared when the component unmounts.\n\n```js\nimport { store, autoEffect, clearEffect } from '@risingstack/react-easy-state';\n\nconst user = store({ name: 'Bob' })\n\nconst effect = autoEffect(() =\u003e document.title = user.name)\nclearEffect(effect)\n```\n\n## Examples with live demos :tv:\n\n#### Beginner\n\n- [Clock Widget](https://risingstack.github.io/react-easy-state/examples/clock/build) ([source](/examples/clock/)) ([codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/clock)) ([react-native source](/examples/native-clock/)) ([react-native sandbox](https://snack.expo.io/@git/github.com/RisingStack/react-easy-state:examples/native-clock)): a reusable clock widget with a tiny local state store.\n- [Stopwatch](https://risingstack.github.io/react-easy-state/examples/stop-watch/build) ([source](/examples/stop-watch/)) ([codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/stop-watch)) ([tutorial](https://hackernoon.com/introducing-react-easy-state-1210a156fa16)): a stopwatch with a mix of normal and getter state properties.\n\n#### Advanced\n\n- [Pokédex](https://risingstack.github.io/react-easy-state/examples/pokedex/build) ([source](/examples/pokedex/)) ([codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/pokedex)): a Pokédex app build with Apollo GraphQL, async actions and a global state.\n- [TodoMVC](https://risingstack.github.io/react-easy-state/examples/todo-mvc/build) ([source](/examples/todo-mvc/)) ([codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/todo-mvc)): a classic TodoMVC implementation with a lot of getters/setters and implicit reactivity.\n- [Contacts Table](https://risingstack.github.io/react-easy-state/examples/contacts/build) ([source](/examples/contacts/)) ([codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/contacts)): a data grid implementation with a mix of global and local state.\n- [Beer Finder](https://risingstack.github.io/react-easy-state/examples/beer-finder/build) ([source](/examples/beer-finder/)) ([codesandbox](https://codesandbox.io/s/github/RisingStack/react-easy-state/tree/master/examples/beer-finder)) ([tutorial](https://medium.com/@solkimicreb/design-patterns-with-react-easy-state-830b927acc7c)): an app with async actions and a mix of local and global state, which finds matching beers for your meal.\n\n## Articles :loudspeaker:\n\n- [Introducing React Easy State](https://blog.risingstack.com/introducing-react-easy-state/): making a simple stopwatch.\n- [Stress Testing React Easy State](https://medium.com/@solkimicreb/stress-testing-react-easy-state-ac321fa3becf): demonstrating Easy State's reactivity with increasingly exotic state mutations.\n- [Design Patterns with React Easy State](https://medium.com/@solkimicreb/design-patterns-with-react-easy-state-830b927acc7c): demonstrating async actions and local and global state management through a beer finder app.\n- [The Ideas Behind React Easy State](https://medium.com/dailyjs/the-ideas-behind-react-easy-state-901d70e4d03e): a deep dive under the hood of Easy State.\n\n## Performance :rocket:\n\nYou can compare Easy State with plain React and other state management libraries with the below benchmarks. It performs a bit better than MobX and similarly to Redux.\n\n- [js-framework-benchmark](https://github.com/krausest/js-framework-benchmark) ([source](https://github.com/krausest/js-framework-benchmark/tree/master/react-v16.1.0-easy-state-v4.0.1-keyed)) ([results](https://rawgit.com/krausest/js-framework-benchmark/master/webdriver-ts-results/table.html))\n\n## Platform support :computer:\n\n- Node: 6 and above\n- Chrome: 49 and above\n- Firefox: 38 and above\n- Safari: 10 and above\n- Edge: 12 and above\n- Opera: 36 and above\n- React Native: 0.59 and above\n\n_This library is based on non polyfillable ES6 Proxies. Because of this, it will never support IE._\n\n## Alternative builds :wrench:\n\nThis library detects if you use ES6 or commonJS modules and serve the right format to you. The default bundles use ES6 features, which may not yet be supported by some minifier tools. If you experience issues during the build process, you can switch to one of the ES5 builds from below.\n\n- `@risingstack/react-easy-state/dist/es.es6.js` exposes an ES6 build with ES6 modules.\n- `@risingstack/react-easy-state/dist/es.es5.js` exposes an ES5 build with ES6 modules.\n- `@risingstack/react-easy-state/dist/cjs.es6.js` exposes an ES6 build with commonJS modules.\n- `@risingstack/react-easy-state/dist/cjs.es5.js` exposes an ES5 build with commonJS modules.\n\nIf you use a bundler, set up an alias for `@risingstack/react-easy-state` to point to your desired build. You can learn how to do it with webpack [here](https://webpack.js.org/configuration/resolve/#resolve-alias) and with rollup [here](https://github.com/rollup/rollup-plugin-alias#usage).\n\n## Contributors :sparkles:\n\nContributions are always welcome, please read our [contributing documentation](CONTRIBUTING.md).\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://bertalan-miklos.now.sh/\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/6956014?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMiklos Bertalan\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=solkimicreb\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=solkimicreb\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=solkimicreb\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#blog-solkimicreb\" title=\"Blogposts\"\u003e📝\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/rolandszoke\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/14181908?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRoland\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=rolandszoke\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=rolandszoke\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=rolandszoke\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/danielgrgly\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/22714514?s=460\u0026u=cbbc2326d5f671693a1f33671d9eadad902d5191\u0026v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDaniel Gergely\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/RisingStack/react-easy-state/commits?author=danielgrgly\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#design-danielgrgly\" title=\"Design\"\u003e🎨\u003c/a\u003e \u003ca href=\"#example-danielgrgly\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/peteyycz\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/7130689?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePeter Czibik\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-peteyycz\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","funding_links":[],"categories":["JavaScript","react","Frameworks"],"sub_categories":["State of the React"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRisingStack%2Freact-easy-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRisingStack%2Freact-easy-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRisingStack%2Freact-easy-state/lists"}