Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 25defd7

Browse files
committed
added simple example & license
1 parent fb01cce commit 25defd7

3 files changed

Lines changed: 110 additions & 3 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-present DaniAkash
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ The simplest state management tool for React. Built completely with React Hooks!
2020

2121
### 🚧 Work in Progress 👷🏽‍♂️🏗
2222

23-
### You are welcome to Install & Try out the project in the mean time!
23+
This library is currently under heavy testing. Hence it is **NOT** recommended for PROD _just yet_... You are welcome to Install & Try out the project in the mean time!
2424

2525
### PRs Welcome 👍✨
2626

2727
</div>
2828

29+
## Motivation
30+
31+
React is a simple and straightforward library for building UI however, the current solutions to manage states aren't quite simple or straightforward as React.
32+
33+
Rex State aims to be the simplest way to manage states in your React Project.
34+
35+
## Requirements
36+
37+
Rex State is built purely on React Hooks hence it requires React > 16.8 to work. It also doesn't work with class components.
38+
2939
## Installation
3040

3141
```sh
@@ -38,6 +48,82 @@ npm i rex-state
3848

3949
## Usage
4050

51+
Rex State is inspired by React's simplicity in building UI. Hence it borrows one of the most common React-ish style for creating & updating states.
52+
53+
### This is a traditional React Class Component
54+
55+
```jsx
56+
import React, { Component } from "react";
57+
58+
export default class InputField extends Component {
59+
constructor() {
60+
super();
61+
this.state = {
62+
value: ""
63+
};
64+
}
65+
66+
updateValue = newValue => this.setState({ value: newValue });
67+
68+
render() {
69+
return (
70+
<input
71+
type="text"
72+
placeholder="Add Text here..."
73+
value={this.state.value}
74+
onChange={event => this.updateValue(event.target.value)}
75+
/>
76+
);
77+
}
78+
}
79+
```
80+
81+
The above component will render a simple input field and will take care of updating the input state when a new value is entered in the input field. However, the state & UI are tightly coupled together and it is impossible to reuse the same state logic to a different UI.
82+
83+
### This is the same component using Rex State
84+
85+
```jsx
86+
import React from "react";
87+
import Rex from "rex-state";
88+
89+
class InputState extends Rex {
90+
constructor() {
91+
super();
92+
this.state = {
93+
value: ""
94+
};
95+
}
96+
97+
get value() {
98+
return this.state.value;
99+
}
100+
101+
updateValue = newValue => this.setState({ value: newValue });
102+
}
103+
104+
const InputField = () => {
105+
const inputState = new InputState();
106+
107+
return (
108+
<input
109+
type="text"
110+
placeholder="Add Text here..."
111+
value={inputState.value}
112+
onChange={event => inputState.updateValue(event.target.value)}
113+
/>
114+
);
115+
};
116+
117+
export default InputField;
118+
```
119+
120+
The functionality of the component remains unchanged, however we now have two entities.
121+
122+
- `InputState` is a class which is used to define your application state.
123+
- `InputField` is a functional React Component that uses `InputState` to render it's UI.
124+
125+
This decouples the UI from the State and also provides a nice & familiar class based API to define & manage your states.
126+
41127
Refer the Example app. Documentation will be completed soon...
42128

43129
### You can also try it live in [**codesandbox!**](https://codesandbox.io/s/state-management-with-rex-4olpn?fontsize=14&hidenavigation=1&theme=dark)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "rex-state",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "The Simplest state management tool for React",
55
"scripts": {
66
"build": "rm -rf ./lib && tsc -p .",
77
"test": "jest"
88
},
99
"main": "lib/index.js",
1010
"author": "DaniAkash <s.daniakash@gmail.com> (https://github.com/DaniAkash)",
11-
"repository": "DaniAkash/rex",
11+
"repository": "DaniAkash/rex-state",
1212
"license": "MIT",
1313
"keywords": [
1414
"react",

0 commit comments

Comments
 (0)