Skip to content

Commit f91ba4e

Browse files
authored
Add name to raw input props (#142)
* update dev environment * add raw name
1 parent 16df900 commit f91ba4e

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
}
3030
}
3131
],
32-
"ignorePatterns": ["test/types.tsx"]
32+
"ignorePatterns": ["test/types.tsx", "rollup.config.js"]
3333
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"hook"
2121
],
2222
"scripts": {
23-
"build": "rollup -c && cp src/index.d.ts dist/index.d.ts",
24-
"build:dev": "rollup -c -w",
23+
"build": "rollup -c",
24+
"build:dev": "rollup -c -w --environment=BUILD:development",
2525
"clean": "rm -rf dist",
2626
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
2727
"lint": "eslint src test",
@@ -71,8 +71,8 @@
7171
"jest": "^24.7.1",
7272
"jest-dom": "^2.1.0",
7373
"prettier": "^1.19.1",
74-
"react": "^16.7.0-alpha.0",
75-
"react-dom": "^16.7.0-alpha.0",
74+
"react": "^16.13.1",
75+
"react-dom": "^16.13.1",
7676
"react-hooks-testing-library": "^0.3.7",
7777
"react-testing-library": "^6.0.0",
7878
"rollup": "^2.10.2",

rollup.config.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
1+
import fs from 'fs';
12
import babel from '@rollup/plugin-babel';
23
import replace from '@rollup/plugin-replace';
34
import pkg from './package.json';
45

6+
const isDevBuild = process.env.BUILD === 'development';
7+
58
export default {
69
input: 'src/index.js',
710
output: [
8-
{
11+
!isDevBuild && {
912
file: pkg.main,
1013
format: 'cjs',
1114
},
1215
{
1316
file: pkg.module,
1417
format: 'es',
18+
sourcemap: isDevBuild,
1519
},
1620
],
17-
external: Object.keys(pkg.devDependencies),
21+
external: Object.keys(pkg.peerDependencies),
1822
plugins: [
1923
babel({
2024
babelHelpers: 'bundled',
2125
}),
2226
replace({
2327
__DEV__: "process.env.NODE_ENV === 'development'",
2428
}),
29+
copyFile('src/index.d.ts', 'dist/index.d.ts'),
2530
],
2631
};
32+
33+
function copyFile(source, dest) {
34+
let called = false;
35+
return {
36+
async writeBundle() {
37+
if (called) return;
38+
called = true;
39+
try {
40+
await fs.promises.copyFile(source, dest);
41+
console.log(`copied ${source}${dest}`);
42+
} catch (err) {
43+
console.log(err);
44+
process.exit(1);
45+
}
46+
},
47+
};
48+
}

src/useFormState.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ export default function useFormState(initialState, options) {
312312
onChange: inputProps.onChange,
313313
onBlur: inputProps.onBlur,
314314
value: inputProps.value,
315+
name: inputProps.name,
315316
};
316317
}
317318

test/useFormState-input.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('input type methods return correct props object', () => {
6161
it('returns props for type "raw"', () => {
6262
const { result } = renderHook(() => useFormState({ option: '' }));
6363
expect(result.current[1].raw('option')).toEqual({
64+
name: 'option',
6465
value: '',
6566
onChange: expect.any(Function),
6667
onBlur: expect.any(Function),
@@ -72,6 +73,7 @@ describe('input type methods return correct props object', () => {
7273
expect(
7374
result.current[1].raw({ name: 'option', touchOnChange: true }),
7475
).toEqual({
76+
name: 'option',
7577
value: expect.any(Date),
7678
onChange: expect.any(Function),
7779
onBlur: expect.any(Function),

yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4843,15 +4843,15 @@ randomatic@^3.0.0:
48434843
kind-of "^6.0.0"
48444844
math-random "^1.0.1"
48454845

4846-
react-dom@^16.7.0-alpha.0:
4847-
version "16.12.0"
4848-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.12.0.tgz#0da4b714b8d13c2038c9396b54a92baea633fe11"
4849-
integrity sha512-LMxFfAGrcS3kETtQaCkTKjMiifahaMySFDn71fZUNpPHZQEzmk/GiAeIT8JSOrHB23fnuCOMruL2a8NYlw+8Gw==
4846+
react-dom@^16.13.1:
4847+
version "16.13.1"
4848+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
4849+
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
48504850
dependencies:
48514851
loose-envify "^1.1.0"
48524852
object-assign "^4.1.1"
48534853
prop-types "^15.6.2"
4854-
scheduler "^0.18.0"
4854+
scheduler "^0.19.1"
48554855

48564856
react-hooks-testing-library@^0.3.7:
48574857
version "0.3.8"
@@ -4874,10 +4874,10 @@ react-testing-library@^6.0.0, react-testing-library@^6.0.2:
48744874
"@babel/runtime" "^7.4.2"
48754875
dom-testing-library "^3.19.0"
48764876

4877-
react@^16.7.0-alpha.0:
4878-
version "16.12.0"
4879-
resolved "https://registry.yarnpkg.com/react/-/react-16.12.0.tgz#0c0a9c6a142429e3614834d5a778e18aa78a0b83"
4880-
integrity sha512-fglqy3k5E+81pA8s+7K0/T3DBCF0ZDOher1elBFzF7O6arXJgzyu/FW+COxFvAWXJoJN9KIZbT2LXlukwphYTA==
4877+
react@^16.13.1:
4878+
version "16.13.1"
4879+
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
4880+
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
48814881
dependencies:
48824882
loose-envify "^1.1.0"
48834883
object-assign "^4.1.1"
@@ -5263,10 +5263,10 @@ sax@^1.2.4:
52635263
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
52645264
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
52655265

5266-
scheduler@^0.18.0:
5267-
version "0.18.0"
5268-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.18.0.tgz#5901ad6659bc1d8f3fdaf36eb7a67b0d6746b1c4"
5269-
integrity sha512-agTSHR1Nbfi6ulI0kYNK0203joW2Y5W4po4l+v03tOoiJKpTBbxpNhWDvqc/4IcOw+KLmSiQLTasZ4cab2/UWQ==
5266+
scheduler@^0.19.1:
5267+
version "0.19.1"
5268+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
5269+
integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==
52705270
dependencies:
52715271
loose-envify "^1.1.0"
52725272
object-assign "^4.1.1"

0 commit comments

Comments
 (0)