Skip to content

Commit 61b1f1d

Browse files
authored
Include nullish props in component schema (#272)
* feat(validation): add validation schema for props with no validation logic in createComponentDefinition function * feat(react): include nullish props in component schema * ensure only nullish props
1 parent 8906dc6 commit 61b1f1d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.changeset/fair-guests-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@playcanvas/react": patch
3+
---
4+
5+
Include nullish props in component schema

packages/lib/src/utils/validation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,15 @@ export function createComponentDefinition<T, InstanceType>(
494494
default: value,
495495
errorMsg: (val) => `Invalid value for prop "${String(key)}": "${JSON.stringify(val)}". Expected a Material.`,
496496
};
497+
} else if(value === null) {
498+
schema[key] = {
499+
validate: () => true,
500+
default: value,
501+
errorMsg: () => '',
502+
apply: (instance, props, key) => {
503+
(instance[key as keyof InstanceType] as unknown) = props[key];
504+
}
505+
};
497506
}
498507
});
499508

0 commit comments

Comments
 (0)