https://github.com/oknoorap/mobx-react-lite-context
Simple MobX React Lite with Context + Hooks
https://github.com/oknoorap/mobx-react-lite-context
mobx-react react
Last synced: 5 months ago
JSON representation
Simple MobX React Lite with Context + Hooks
- Host: GitHub
- URL: https://github.com/oknoorap/mobx-react-lite-context
- Owner: oknoorap
- License: mit
- Created: 2019-06-18T00:01:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-21T08:13:40.000Z (over 6 years ago)
- Last Synced: 2025-08-18T03:06:54.088Z (6 months ago)
- Topics: mobx-react, react
- Language: TypeScript
- Homepage:
- Size: 13.7 KB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
MobX React Lite Context
> Simple MobX React Lite with Context
## Install
```sh
# yarn
yarn add mobx mobx-react-lite mobx-react-lite-context
# npm
npm install mobx mobx-react-lite mobx-react-lite-context --save
```
## Example
More example via [codesandbox.io](https://codesandbox.io/s/mobx-react-lite-context-3iwcu)
```tsx
// index.tsx
import React from 'react'
import ReactDOM from 'react-dom'
import Page from './page'
import Store from './store'
const App = () => {
return (
);
};
ReactDOM.render(, document.getElementById("root"));
// page.tsx
import React from 'react'
import Store, { IStore } from './store'
export default () => {
const { counter }: IStore = useStore()
return (
counter.add()}>Increment {counter.value}
)
}
// store.ts
import { createContext } from "mobx-react-lite-context";
import Counter, { IStore as ICounterStore } from "./counter";
export interface IStore {
counter: ICounterStore;
}
export default createContext({
counter: new Counter()
});
// counter.ts
import { observable, action } from 'mobx'
interface IStore {
value: number;
add(): void;
}
export default class Store implements IStore {
@observable value = 0;
@action add() {
this.value++;
}
}
```
## 💰 Donate
Send me ETH to this address `0xab1c4e446900ad20bf5fae1be67f87d54dacd2f0`
## Author
👤 **Ribhararnus Pracutian <oknoorap@gmail.com>**
* Twitter: [@oknoorap](https://twitter.com/oknoorap)
* Github: [@oknoorap](https://github.com/oknoorap)
## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/oknoorap/mobx-react-lite-context/issues).
## Show your support
Give a ⭐️ if this project helped you!
## License
MIT © oknoorap