Skip to content

Commit

Permalink
fix bugs of connect && useAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
jilin.jin committed Aug 7, 2019
1 parent 775c69a commit 105139e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
@@ -1,5 +1,5 @@
# dva-react-hook
[![NPM](https://img.shields.io/badge/npm-v1.1.2-blue)](https://www.npmjs.com/package/dva-react-hook)
[![NPM](https://img.shields.io/badge/npm-v1.1.3-blue)](https://www.npmjs.com/package/dva-react-hook)
[![size](https://img.shields.io/badge/size-17KB-green)]()
> React Hooks based, imitating dva, lightweight framework.
Expand Down Expand Up @@ -199,8 +199,8 @@ loginaction({name,pass}).then(data => {
If you are obsessed with writing classes and have no other state management tools, I provide the connect decorator.
The connect decorator receives two arguments, the first is required and the second is optional.
The first argument is useModel's argument
The second argument is useDispatch' argument
The first argument is as same as useModel's argument
The second argument is as same as useDispatch's argument
In your class component,you will have three new props: hookState、setHookState、dispatch
```javascript
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dva-react-hook",
"version": "1.1.2",
"version": "1.1.3",
"description": "React Hooks based, imitating dva, lightweight framework",
"main": "dist/index.js",
"scripts": {},
Expand Down
5 changes: 3 additions & 2 deletions src/connect/index.js
@@ -1,11 +1,12 @@
import React from 'react';
import useHState from '../useHState';
import useModel from '../useModel';
import useDispatch from '../useDispatch';
function connect(model,action){
useHState();
return (Component) => {
return (props) =>{
const [ state,setState ] = useModel(model);
useHState();
const [ {value: state},setState ] = useModel(model);
const dispatch = action ? useDispatch(action) : null;
return <Component hookState = { state } setHookState={ setState } dispatch={dispatch} {...props}/>
}
Expand Down
6 changes: 3 additions & 3 deletions src/useAdd/index.js
Expand Up @@ -12,11 +12,11 @@ export default function useAdd(name, initdate, once){
}
useHState();
const dispatch = useDispatcher()
if (runtime_state === undefined || dispatch === undefined) {
if (store.runtime_state === undefined || dispatch === undefined) {
throw new Error('useAdd must be used within a Provider')
}
if(runtime_state.hasOwnProperty(name)){
throw new Error(`you have already added the state name -- ${name} before !`)
if(store.runtime_state.hasOwnProperty(name)){
console.warn(`you have already added the state name -- ${name} before !`)
}
let data = initdate;
if(typeof initdate === 'function'){
Expand Down

0 comments on commit 105139e

Please sign in to comment.