Skip to content

Commit 816b1b8

Browse files
committed
more
1 parent 53fc679 commit 816b1b8

10 files changed

+22
-22
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/
1+
src/
2+
test/
File renamed without changes.

.nyc_output/b6c5faec-c4cc-467c-9f96-4943f8c5da54.json renamed to .nyc_output/f87f99cb-1220-4a09-b453-b6f80a360070.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"uuid":"9a889e5a-e32a-4e37-9057-00df28a0f0af","parent":null,"pid":36126,"argv":["/Users/mydspr/.nvm/versions/node/v10.11.0/bin/node","/Users/mydspr/Developer/Repos/use-state-with-callback/node_modules/.bin/mocha","--require","@babel/register","--require","./test/dom.js","src/**/**spec.js"],"execArgv":[],"cwd":"/Users/mydspr/Developer/Repos/use-state-with-callback","time":1559299193251,"ppid":36117,"root":"7549c1ec-8d72-4c47-9846-9f76f8d2e0b7","coverageFilename":"/Users/mydspr/Developer/Repos/use-state-with-callback/.nyc_output/9a889e5a-e32a-4e37-9057-00df28a0f0af.json","files":[]}

.nyc_output/processinfo/c0a3be56-c840-4cdf-98d9-77263f182816.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nyc_output/processinfo/b6c5faec-c4cc-467c-9f96-4943f8c5da54.json renamed to .nyc_output/processinfo/f87f99cb-1220-4a09-b453-b6f80a360070.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"uuid":"b6c5faec-c4cc-467c-9f96-4943f8c5da54","parent":"c0a3be56-c840-4cdf-98d9-77263f182816","pid":26507,"argv":["/Users/mydspr/.nvm/versions/node/v10.11.0/bin/node","/Users/mydspr/Developer/Repos/use-state-with-callback/node_modules/mocha/bin/_mocha","src/**/**spec.js","--require","@babel/register","--require","./test/dom.js","--no-config","--no-package","--no-opts","--diff","--extension","js","--reporter","spec","--slow","75","--timeout","2000","--ui","bdd"],"execArgv":[],"cwd":"/Users/mydspr/Developer/Repos/use-state-with-callback","time":1559297832448,"ppid":26502,"root":"6f7c4597-2b95-43f0-a27b-f9249a0e4614","coverageFilename":"/Users/mydspr/Developer/Repos/use-state-with-callback/.nyc_output/b6c5faec-c4cc-467c-9f96-4943f8c5da54.json","files":["/Users/mydspr/Developer/Repos/use-state-with-callback/src/spec.js","/Users/mydspr/Developer/Repos/use-state-with-callback/src/index.js"]}
1+
{"uuid":"f87f99cb-1220-4a09-b453-b6f80a360070","parent":"9a889e5a-e32a-4e37-9057-00df28a0f0af","pid":36129,"argv":["/Users/mydspr/.nvm/versions/node/v10.11.0/bin/node","/Users/mydspr/Developer/Repos/use-state-with-callback/node_modules/mocha/bin/_mocha","src/**/**spec.js","--require","@babel/register","--require","./test/dom.js","--no-config","--no-package","--no-opts","--diff","--extension","js","--reporter","spec","--slow","75","--timeout","2000","--ui","bdd"],"execArgv":[],"cwd":"/Users/mydspr/Developer/Repos/use-state-with-callback","time":1559299194001,"ppid":36126,"root":"7549c1ec-8d72-4c47-9846-9f76f8d2e0b7","coverageFilename":"/Users/mydspr/Developer/Repos/use-state-with-callback/.nyc_output/f87f99cb-1220-4a09-b453-b6f80a360070.json","files":["/Users/mydspr/Developer/Repos/use-state-with-callback/src/spec.js","/Users/mydspr/Developer/Repos/use-state-with-callback/src/index.js"]}

.nyc_output/processinfo/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"processes":{"b6c5faec-c4cc-467c-9f96-4943f8c5da54":{"parent":"c0a3be56-c840-4cdf-98d9-77263f182816","children":[]},"c0a3be56-c840-4cdf-98d9-77263f182816":{"parent":null,"children":["b6c5faec-c4cc-467c-9f96-4943f8c5da54"]}},"files":{"/Users/mydspr/Developer/Repos/use-state-with-callback/src/spec.js":["b6c5faec-c4cc-467c-9f96-4943f8c5da54"],"/Users/mydspr/Developer/Repos/use-state-with-callback/src/index.js":["b6c5faec-c4cc-467c-9f96-4943f8c5da54"]},"externalIds":{}}
1+
{"processes":{"9a889e5a-e32a-4e37-9057-00df28a0f0af":{"parent":null,"children":["f87f99cb-1220-4a09-b453-b6f80a360070"]},"f87f99cb-1220-4a09-b453-b6f80a360070":{"parent":"9a889e5a-e32a-4e37-9057-00df28a0f0af","children":[]}},"files":{"/Users/mydspr/Developer/Repos/use-state-with-callback/src/spec.js":["f87f99cb-1220-4a09-b453-b6f80a360070"],"/Users/mydspr/Developer/Repos/use-state-with-callback/src/index.js":["f87f99cb-1220-4a09-b453-b6f80a360070"]},"externalIds":{}}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "use-state-with-callback",
3-
"version": "1.0.5",
3+
"version": "1.0.14",
44
"description": "",
55
"main": "lib/index.js",
66
"scripts": {
@@ -13,8 +13,8 @@
1313
"author": "“Robin <hello@rwieruch.com”> (https://www.robinwieruch.de)",
1414
"license": "MIT",
1515
"peerDependencies": {
16-
"react": "^16.8.5",
17-
"react-dom": "^16.8.5"
16+
"react": "^16.8.6",
17+
"react-dom": "^16.8.6"
1818
},
1919
"devDependencies": {
2020
"@babel/cli": "^7.4.4",
@@ -45,6 +45,5 @@
4545
"bugs": {
4646
"url": "https://github.com/the-road-to-learn-react/use-combined-reducers/issues"
4747
},
48-
"homepage": "https://github.com/the-road-to-learn-react/use-combined-reducers#readme",
49-
"dependencies": {}
48+
"homepage": "https://github.com/the-road-to-learn-react/use-combined-reducers#readme"
5049
}

src/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { useState, useEffect, useLayoutEffect } from 'react';
1+
import React, { useState, useEffect, useLayoutEffect } from 'react';
22

3-
const useStateWithCallbackBlueprint = effect => (
4-
initialState,
5-
callback,
6-
) => {
3+
const useStateWithCallback = (initialState, callback) => {
74
const [state, setState] = useState(initialState);
85

9-
effect(() => callback(state), [state, callback]);
6+
useEffect(() => callback(state), [state, callback]);
107

118
return [state, setState];
129
};
1310

14-
const useStateWithCallback = useStateWithCallbackBlueprint(useEffect);
15-
const useStateWithCallbackInstant = useStateWithCallbackBlueprint(
16-
useLayoutEffect,
17-
);
11+
const useStateWithCallbackInstant = (initialState, callback) => {
12+
const [state, setState] = useState(initialState);
13+
14+
useLayoutEffect(() => callback(state), [state, callback]);
15+
16+
return [state, setState];
17+
};
1818

1919
export { useStateWithCallbackInstant };
2020

0 commit comments

Comments
 (0)