Skip to content

Commit 3b28b3a

Browse files
authored
Merge pull request #4 from trblackw/patch-1
grammatical edits/rephrasings
2 parents 943561a + 8559c2e commit 3b28b3a

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

README.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# <img src='https://raw.githubusercontent.com/iusehooks/redhooks/master/logo/logo.png' width="224" height='61' alt='Redhooks Logo' />
22

33
Redhooks is tiny React utility library for holding a predictable state container in your React apps.
4-
Inspired by [Redux](https://redux.js.org), it reimplements redux concept by using the experimental Hooks API and the Context API.
5-
4+
Inspired by [Redux](https://redux.js.org), it reimplements the redux paradigm of state-management by using React's new Hooks and Context API, which have recently been [officially approved](https://github.com/facebook/react/pull/14679) by the React team.
65
- [Motivation](#motivation)
76
- [Basic Example](#basic-example)
87
- [Apply Middleware](#apply-middleware)
@@ -21,17 +20,17 @@ npm install --save redhooks
2120

2221
# Motivation
2322

24-
In the [Reactjs docs](https://reactjs.org/docs/hooks-custom.html) a nice paragraph titled useYourImagination() suggests to think on differents possible usages of the Hooks, this essentially is what Redhooks tries to do.
25-
Redhooks does not use any third party library, it only depends on the new Hooks and the Context API.
26-
You do not need to install `react-redux` to connect your components to the store because you can have access to it directly from any of your function components by calling `useStore` Redhooks api.
27-
Hooks are not allowed within class Components, for using the store within them Redhooks exposes a HOC named `connect`.
28-
It also supports the use of middlewares like `redux-thunk` or `redux-saga` or your custom middleware conforming to the middleware's API.
23+
In the [Reactjs docs](https://reactjs.org/docs/hooks-custom.html) a nice paragraph titled _useYourImagination()_ suggests to think of different possible usages of functionality Hooks provide, which is essentially what Redhooks tries to do.
24+
This package does not use any third party library, being only dependendent upon the Hooks and the Context API.
25+
You do not need to install `react-redux` to connect your components to the store because you can have access to it directly from any of your function components by utilizing the `useStore` Redhooks API.
26+
Hooks are [not allowed within class Components](https://reactjs.org/docs/hooks-rules.html), for using the store within them Redhooks exposes a Higher Order Component (HOC) named `connect`.
27+
It also supports the use of middleware like `redux-thunk` or `redux-saga` or your own custom middleware conforming to the middleware's API.
2928

3029
# Basic Example
3130

32-
Redhooks follows the exact same principles of redux which is inspired to.
33-
* the whole state of your app is stored in an object tree inside a single store.
34-
* state is read only. So the only way to change the state is to dispatch an action, an object describing what happened.
31+
Redhooks follows the exact same principles of redux, which was the package's inspiration.
32+
* the total state of your app is stored in an object tree inside of a single store object.
33+
* state is _read only_, so the only way to change the state is to dispatch an [action](https://redux.js.org/basics/actions), an object describing the changes to be made to the state.
3534
* to specify how the actions transform the state tree, you write pure reducers.
3635

3736
## Store
@@ -98,9 +97,9 @@ const rootElement = document.getElementById("root");
9897
ReactDOM.render(<App />, rootElement);
9998
```
10099

101-
## Dispatching Sync and Async Actions - No expensive rendering operation
102-
If your component does not perform an expensive rendering you can use `useStore` Redhooks API within your
103-
function Component in order to have access to the Redhooks store. Class or function components that perform expensive rendering operations can be connected to the store by using `connect` Redhooks HOC which takes care to avoid unnecessary re-rendering in order to improve the performance. But we will see it in action in the next paragraph.
100+
## Dispatching Sync and Async Actions - Non-expensive rendering operation
101+
If your component does not require expensive rendering, you can use the `useStore` Redhooks API within your
102+
functional component in order to access the Redhooks store. Class or function components that perform expensive rendering operations can be connected to the store by using the `connect` Redhooks HOC which takes care to avoid unnecessary re-rendering in order to improve performance. We'll be able to see this in action below:
104103

105104
`./components/DispatchAction.js`
106105
```js
@@ -139,7 +138,7 @@ export default DispatchAction;
139138
```
140139

141140
## Dispatching Sync and Async Actions - Expensive rendering operation
142-
For components wich perform expensive rendering the use of `connect` HOC helps to avoid unnecessary re-renders.
141+
For components requiring expensive rendering, the use of `connect` helps to avoid any unnecessary re-rendering.
143142

144143
`./components/DispatchActionExpensive.js`
145144
```js
@@ -185,7 +184,7 @@ const ReadFromStore = () => {
185184
export default ReadFromStore;
186185
```
187186

188-
> **Tips**: If your function component performs a expensive rendering you should use the `connect` HOC Redhooks API.
187+
> **Tip**: If your function component requires an expensive render, you should use the `connect` HOC Redhooks API.
189188
190189
## Use Store from a Class Component
191190

@@ -217,8 +216,8 @@ export default connect(mapStateToProp)(ReadFromStore);
217216

218217
# Apply Middleware
219218

220-
As for Redux, middleware is a way to extend Redhooks with custom functionality.
221-
Middleware are functions which receive Store's `dispatch` and `getState` as named arguments, and return a function. Redhooks supports the use of the redux's middlewares like `redux-thunk`, `redux-saga` or you migth write a custom middleware conforming to middleware API.
219+
As for Redux, [middleware](https://redux.js.org/advanced/middleware) is a way to extend Redhooks with custom functionality.
220+
Middleware are functions which receive the store's `dispatch` and `getState` as named arguments, and subsequently return a function. Redhooks supports the use of redux middleware like `[redux-thunk](https://www.npmjs.com/package/redux-thunk)`, `[redux-saga](https://www.npmjs.com/package/redux-saga)` or you could write custom middleware to conform to the middleware API.
222221

223222
## Custom middleware - Logger Example
224223

@@ -369,9 +368,9 @@ ReactDOM.render(<App />, rootElement);
369368
createStore(reducer, [opts])
370369
```
371370
`createStore` returns the store object to be passed to the `<Provider store={store} />`.
372-
* The `reducer` argument might be a single reducer function, a function returned by `combineReducers` or a plain object whose values are reducer functions if your store needs multiple reducers.
371+
* The `reducer` argument might be a single reducer function, a function returned by `combineReducers` or a plain object whose values are reducer functions (if your store requires multiple reducers).
373372
* The `opts` optional argument is an object which allows you to pass a `preloadedState`, `initialAction` and `middlewares`.
374-
> The store is ready after the Provider is mounted, an `onload` event will be triggered at that time.
373+
> The store is ready when the `Provider` is mounted, after which an `onload` event will be triggered.
375374
376375
#### Example
377376
```js
@@ -401,10 +400,10 @@ const store = createStore(rootReducer)
401400
```js
402401
connect([mapStateToProps], [mapDispatchToProps])
403402
```
404-
`connect` function connects a React component to a Redhooks store. It returns a connected component class that wraps the component you passed in taking care to avoid unnecessary re-rendering. It should be used if your class or function components perform expensive rendering.
403+
`connect` function connects a React component to a Redhooks store. It returns a connected component class that wraps the component you passed in taking care to avoid unnecessary re-rendering. It should be used if your class or function components require expensive rendering.
405404

406-
* If a `mapStateToProps` function is passed, your component will be subscribed to Redhooks store. Any time the store is updated, mapStateToProps will be called. The results of mapStateToProps must be a plain object, which will be merged into your component’s props. If you don't want to connect to Redhooks store, pass null or undefined in place of mapStateToProps.
407-
* `mapDispatchToProps` if passed may be either a function that must return a plain object whose values are functions or a plain object whose values are [action creator](#action-creator) functions. In both cases the props of the returned object will be merged in your component’s props. If is not passed your component will receive `dispatch` prop by default.
405+
* If a `mapStateToProps` function is passed, your component will be subscribed to Redhooks store. Any time the store is updated, `mapStateToProps` will be called. The results of `mapStateToProps` must be a plain object, which will be merged into your component’s props. If you don't want to connect to Redhooks store, pass null or undefined in place of mapStateToProps.
406+
* `mapDispatchToProps`, if passed, may be either a function that returns a plain object whose values, themselves, are functions or a plain object whose values are [action creator](#action-creator) functions. In both cases the props of the returned object will be merged in your component’s props. If is not passed your component will receive `dispatch` prop by default.
408407

409408
#### Example
410409
```js
@@ -421,12 +420,12 @@ export default connect(mapStateToProps, mapDispatchToProps)(ReactComponent)
421420
bindActionCreators(actionCreators, dispatch)
422421
```
423422

424-
`bindActionCreators` turns an object whose values are [action creator](#action-creator), into an object with the
425-
same keys, but with every function wrapped into a `dispatch` call so they
423+
`bindActionCreators` turns an object whose values are [action creators](#action-creator) into an object with the
424+
same keys, but with every function wrapped in a `dispatch` call so they
426425
may be invoked directly.
427426

428427
* `actionCreators` An object whose values are action creator functions or plain objects whose values are action creator functions
429-
* `dispatch` it is the dispatch function available on your Redhooks store.
428+
* `dispatch` The dispatch function available on your Redhooks store.
430429

431430
#### Action creator
432431
An action creator is a function that creates an action.

0 commit comments

Comments
 (0)