react-redux-hooks
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.1.1"></a> | ||
## [0.1.1](https://github.com/jessy1092/react-redux-hooks/compare/v0.1.0...v0.1.1) (2018-12-12) | ||
### Bug Fixes | ||
* Get redux state before first render ([c9a8477](https://github.com/jessy1092/react-redux-hooks/commit/c9a8477)) | ||
<a name="0.1.0"></a> | ||
@@ -7,0 +17,0 @@ # 0.1.0 (2018-10-26) |
@@ -11,8 +11,8 @@ import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
export var useRedux = function useRedux() { | ||
var _useState = useState({}), | ||
var context = useContext(ReduxContext); | ||
var _useState = useState(context.getState()), | ||
state = _useState[0], | ||
setState = _useState[1]; | ||
var context = useContext(ReduxContext); | ||
function handleChange() { | ||
@@ -19,0 +19,0 @@ setState(context.getState()); |
@@ -24,8 +24,8 @@ "use strict"; | ||
var useRedux = function useRedux() { | ||
var _useState = (0, _react.useState)({}), | ||
var context = (0, _react.useContext)(ReduxContext); | ||
var _useState = (0, _react.useState)(context.getState()), | ||
state = _useState[0], | ||
setState = _useState[1]; | ||
var context = (0, _react.useContext)(ReduxContext); | ||
function handleChange() { | ||
@@ -32,0 +32,0 @@ setState(context.getState()); |
{ | ||
"name": "react-redux-hooks", | ||
"description": "The easiest way to connect redux. Power by react hooks", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"keywords": [ | ||
"react", | ||
"redux", | ||
"react hooks", | ||
"hook" | ||
"react", | ||
"redux", | ||
"react hooks", | ||
"hook" | ||
], | ||
@@ -25,4 +25,4 @@ "contributor": [ | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist-es/index.js", | ||
"main": "dist/index.js", | ||
"module": "dist-es/index.js", | ||
"jsnext:main": "dist-es/index.js", | ||
@@ -38,4 +38,4 @@ "scripts": { | ||
"commit": "git-cz", | ||
"release": "standard-version", | ||
"prepublish": "yarn build && yarn build:es", | ||
"release": "standard-version", | ||
"prepublish": "yarn build && yarn build:es", | ||
"format": "prettier --config ./.prettierrc --write \"./{,**/}/*.{js,css,json}\" && eslint --fix ." | ||
@@ -109,5 +109,5 @@ }, | ||
"**/src/**/*.stories.js", | ||
"**/src/**/*.spec.js", | ||
"**/storybook/**/*.spec.js", | ||
"**/storybook/**/*.spec.js" | ||
"**/src/**/*.spec.js", | ||
"**/storybook/**/*.spec.js", | ||
"**/storybook/**/*.spec.js" | ||
], | ||
@@ -114,0 +114,0 @@ "automock": false, |
react-redux-hooks | ||
===== | ||
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/) [![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg?style=flat-square)](https://github.com/conventional-changelog/standard-version) | ||
[![Commitizen friendly][commitizen-image]][commitizen-image] [![Standard Version][standard-version-image]][standard-version-url] [![npm][npm-image]][npm-url] [![Dependency Status][david-dm-image]][david-dm-url] | ||
@@ -10,2 +10,16 @@ The easiest way to connect redux. Power by [react hooks](https://reactjs.org/docs/hooks-intro.html). | ||
### Install | ||
``` | ||
npm install react-redux-hooks | ||
``` | ||
or | ||
``` | ||
yarn add react-redux-hooks | ||
``` | ||
### Usage | ||
#### Connect to redux in component | ||
@@ -22,3 +36,3 @@ | ||
return ( | ||
<button onClick={() => dispatch({ type: 'TOOGLE' })}> | ||
<button onClick={() => dispatch({ type: 'TOGGLE' })}> | ||
{state.toggle ? 'Click to close' : 'Click to open'} | ||
@@ -40,3 +54,3 @@ </button> | ||
const store = createStore((state = { toggle: false }, action) => { | ||
if (action.type === 'TOOGLE') { | ||
if (action.type === 'TOGGLE') { | ||
return { toggle: !state.toggle }; | ||
@@ -56,1 +70,61 @@ } | ||
``` | ||
## Roadmap | ||
- Shallow compare | ||
- Customize Selector | ||
Discussion welcome to [open issue](https://github.com/jessy1092/react-redux-hooks/issues) | ||
## Release Notes | ||
see [CHANGELOG.md](https://github.com/jessy1092/react-redux-hooks/blob/master/CHANGELOG.md) | ||
## Contribute | ||
[![devDependency Status][david-dm-dev-image]][david-dm-dev-url] | ||
1. Fork it. | ||
2. Create your feature-branch `git checkout -b your-new-feature-branch` | ||
3. Commit your change `git commit -am 'Add new feature'` | ||
4. Push to the branch `git push origin your-new-feature-branch` | ||
5. Create new Pull Request with `master` branch | ||
## License | ||
The MIT License (MIT) | ||
Copyright (c) 2018 Lee < jessy1092@gmail.com > | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[commitizen-image]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square | ||
[commitizen-url]: http://commitizen.github.io/cz-cli/ | ||
[standard-version-image]: https://img.shields.io/badge/release-standard%20version-brightgreen.svg?style=flat-square | ||
[standard-version-url]: https://github.com/conventional-changelog/standard-version | ||
[npm-image]: https://img.shields.io/npm/v/react-redux-hooks.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/react-redux-hooks | ||
[david-dm-image]: https://david-dm.org/jessy1092/react-redux-hooks.svg?style=flat-square | ||
[david-dm-url]: https://david-dm.org/jessy1092/react-redux-hooks | ||
[david-dm-dev-image]: https://david-dm.org/jessy1092/react-redux-hooks/dev-status.svg?style=flat-square | ||
[david-dm-dev-url]: https://david-dm.org/jessy1092/react-redux-hooks#info=devDependencies |
@@ -10,4 +10,4 @@ import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
export const useRedux = () => { | ||
const [state, setState] = useState({}); | ||
const context = useContext(ReduxContext); | ||
const [state, setState] = useState(context.getState()); | ||
@@ -14,0 +14,0 @@ function handleChange() { |
@@ -11,3 +11,3 @@ import React from 'react'; | ||
const store = createStore((state = { toggle: false }, action) => { | ||
if (action.type === 'TOOGLE') { | ||
if (action.type === 'TOGGLE') { | ||
return { toggle: !state.toggle }; | ||
@@ -30,3 +30,3 @@ } | ||
const store = createStore((state = { toggle: false }, action) => { | ||
if (action.type === 'TOOGLE') { | ||
if (action.type === 'TOGGLE') { | ||
return { toggle: !state.toggle }; | ||
@@ -33,0 +33,0 @@ } |
@@ -15,3 +15,3 @@ import React from 'react'; | ||
const store = createStore((state = { toggle: false }, action) => { | ||
if (action.type === 'TOOGLE') { | ||
if (action.type === 'TOGGLE') { | ||
return { toggle: !state.toggle }; | ||
@@ -18,0 +18,0 @@ } |
@@ -9,3 +9,3 @@ import React from 'react'; | ||
return ( | ||
<button onClick={() => dispatch({ type: 'TOOGLE' })}> | ||
<button onClick={() => dispatch({ type: 'TOGGLE' })}> | ||
{state.toggle ? 'Click to close' : 'Click to open'} | ||
@@ -12,0 +12,0 @@ </button> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
358040
23
127