Skip to content

Commit bfb9b95

Browse files
authored
Merge pull request #1 from oslabs-beta/time-travel-with-conditional-state-fields-bug
Fixed time travel with conditional state fields
2 parents afc59e4 + 117055f commit bfb9b95

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

package/timeJump.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ module.exports = (origin, mode) => {
1616
const originNode = traverseTree(origin.tree, coords);
1717
// set the state of the origin tree if the component is stateful
1818
if (originNode.component.setState) {
19-
originNode.component.setState(target.state, () => {
19+
originNode.component.setState((prevState) => {
20+
Object.keys(prevState).forEach((key) => {
21+
if (target.state[key] === undefined) {
22+
target.state[key] = undefined;
23+
}
24+
})
25+
return target.state;
26+
}, () => {
2027
// iterate through new children once state has been set
2128
target.children.forEach((child, i) => {
2229
jump(child, coords.concat(i));

0 commit comments

Comments
 (0)