Skip to content

Commit 35ec85b

Browse files
committed
handleChange works with checkboxes too
1 parent ea026af commit 35ec85b

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-step-builder",
33
"description": "Unopinionated multi step interface builder.",
44
"author": "Samet Mutevelli <[email protected]> (https://sametmutevelli.com)",
5-
"version": "1.1.11",
5+
"version": "1.1.12",
66
"private": false,
77
"devDependencies": {
88
"@babel/cli": "^7.8.4",

src/App.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const Step1 = (props) => {
1919
value={props.getState("lastname")}
2020
onChange={props.handleChange}
2121
/>
22+
Over 18?{" "}
23+
<input
24+
type="checkbox"
25+
name="over18"
26+
checked={props.getState("over18")}
27+
onChange={props.handleChange}
28+
/>
2229
<span>
2330
<button
2431
data-testid="green"

src/lib/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export function useStepState(INITIAL_VALUE) {
1313
* @param {string} value - Data to be stored.
1414
*/
1515
function setStepState(key, value) {
16-
state[key] = value;
17-
setState(state);
16+
var new_state = JSON.parse(JSON.stringify(state));
17+
new_state[key] = value;
18+
setState(new_state);
1819
}
1920

2021
/**
@@ -36,7 +37,10 @@ export function useStepState(INITIAL_VALUE) {
3637
3738
*/
3839
var key = event.target.name,
39-
value = event.target.value;
40+
value =
41+
event.target.type === "checkbox"
42+
? event.target.checked
43+
: event.target.value;
4044

4145
var new_state = JSON.parse(JSON.stringify(state));
4246
new_state[key] = value;

0 commit comments

Comments
 (0)