Skip to content

Commit

Permalink
docs: fix typos in useStateWithHistory.md
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich authored Feb 21, 2020
2 parents a4a8ad7 + f049d91 commit f63c779
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions docs/useStateWithHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ Stores defined amount of previous state values and provides handles to travel th
```typescript
const [state, setState, stateHistory] = useStateWithHistory<S = undefined>(
initialState?: S | (()=>S),
historyCapacity?: number = 10,
capacity?: number = 10,
initialHistory?: S
);
```

- **`state`**, **`setState`** and **`initialState`** are exactly the same with native React's `useState` hook;
- **`historyCapacity`** - amount of history entries that hold by storage;
- **`initialHistory`** - if defined it will be used as initial history value, otherwise history will equals `[ initialState ]`.
- **`capacity`** - amount of history entries held by storage;
- **`initialHistory`** - if defined it will be used as initial history value, otherwise history will equal `[ initialState ]`.
Initial state will not be pushed to initial history.
If entries amount is greater than `historyCapacity` parameter it wont be modified on init but will be trimmed on next `setState`;
If entries amount is greater than `capacity` parameter it won't be modified on init but will be trimmed on the next call to `setState`;
- **`stateHistory`** - an object containing history state:
- **`history`**_`: S[]`_ - an array holding history entries. _I will have the same ref all the time so pe careful with that one!_;
- **`history`**_`: S[]`_ - an array holding history entries. _It will have the same ref all the time so be careful with that one!_;
- **`position`**_`: number`_ - current position _index_ in history;
- **`capacity`**_`: number = 10`_ - maximum amount of history entries;
- **`back`**_`: (amount?: number) => void`_ - go back in state history, it will cause `setState` invoke and component re-render.
- **`back`**_`: (amount?: number) => void`_ - go back in state history, it will cause `setState` to be invoked and component re-render.
If first element of history reached, the call will have no effect;
- **`forward`**_`: (amount?: number) => void`_ - go forward in state history, it will cause `setState` invoke and component re-render.
If last element of history reached, the call will have no effect;
- **`forward`**_`: (amount?: number) => void`_ - go forward in state history, it will cause `setState` to be invoked and component re-render.
If last element of history is reached, the call will have no effect;
- **`go`**_`: (position: number) => void`_ - go to arbitrary position in history.
In case `position` is non-negative ot will count elements from beginning.
Negative `position` will cause elements counting from the end, so `go(-2)` equals `go(history.length - 1)`;
Expand Down

0 comments on commit f63c779

Please sign in to comment.