Skip to content

Commit bbbd3ff

Browse files
committed
Fix initial value problem
1 parent 84a3aef commit bbbd3ff

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { useEffect, useReducer } from 'react';
44
// useReducer: Used to extract relevant values from the store
55
// useEffect is used to attach a listener to the store
66

7-
export function useFluxStore(store, storeReducer) {
7+
export function useFluxStore(store, reducer) {
88
// Call useReducer and set initial value from current state of store.
9-
const [out, _dispatch] = useReducer(storeReducer);
9+
10+
// We need to pass reducer(null, store) as initialArg otherwise the first out will be undefined
11+
const [out, _dispatch] = useReducer(reducer, reducer(null, store));
1012

1113
useEffect(() => {
1214
function listener() {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flux-hooks",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Hooks implementation for Facebook Flux Util's Stores",
55
"main": "index.js",
66
"scripts": {
@@ -9,8 +9,8 @@
99
"author": "Nav Patel <[email protected]>",
1010
"license": "ISC",
1111
"peerDependencies": {
12-
"react": "^16.8.0",
13-
"flux": "^3.1.2"
12+
"flux": "^3.1.2",
13+
"react": "^16.8.0"
1414
},
1515
"repository": {
1616
"type": "git",

yarn.lock

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ eslint-module-utils@^2.4.0:
308308
pkg-dir "^2.0.0"
309309

310310
eslint-plugin-import@^2.17.2:
311-
version "2.17.2"
312-
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.17.2.tgz#d227d5c6dc67eca71eb590d2bb62fb38d86e9fcb"
313-
integrity sha512-m+cSVxM7oLsIpmwNn2WXTJoReOF9f/CtLMo7qOVmKd1KntBy0hEcuNZ3erTmWjx+DxRO0Zcrm5KwAvI9wHcV5g==
311+
version "2.17.3"
312+
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.17.3.tgz#00548b4434c18faebaba04b24ae6198f280de189"
313+
integrity sha512-qeVf/UwXFJbeyLbxuY8RgqDyEKCkqV7YC+E5S5uOjAp4tOc8zj01JP3ucoBM8JcEqd1qRasJSg6LLlisirfy0Q==
314314
dependencies:
315315
array-includes "^3.0.3"
316316
contains-path "^0.1.0"
@@ -322,7 +322,7 @@ eslint-plugin-import@^2.17.2:
322322
lodash "^4.17.11"
323323
minimatch "^3.0.4"
324324
read-pkg-up "^2.0.0"
325-
resolve "^1.10.0"
325+
resolve "^1.11.0"
326326

327327
eslint-plugin-jsx-a11y@^6.2.1:
328328
version "6.2.1"
@@ -1009,7 +1009,14 @@ resolve-from@^4.0.0:
10091009
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
10101010
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
10111011

1012-
resolve@^1.10.0, resolve@^1.10.1, resolve@^1.5.0:
1012+
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.5.0:
1013+
version "1.11.1"
1014+
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.11.1.tgz#ea10d8110376982fef578df8fc30b9ac30a07a3e"
1015+
integrity sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==
1016+
dependencies:
1017+
path-parse "^1.0.6"
1018+
1019+
resolve@^1.10.1:
10131020
version "1.10.1"
10141021
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.1.tgz#664842ac960795bbe758221cdccda61fb64b5f18"
10151022
integrity sha512-KuIe4mf++td/eFb6wkaPbMDnP6kObCaEtIDuHOUED6MNUo4K670KZUHuuvYPZDxNF0WVLw49n06M2m2dXphEzA==

0 commit comments

Comments
 (0)