Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit b9d3375

Browse files
committed
Refactoring propTypes on Errors component. Fixes #491
1 parent 73d3e91 commit b9d3375

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

src/components/errors-component.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ const defaultStrategy = {
2323
getFieldFromState,
2424
};
2525

26+
const propTypes = {
27+
// Computed props
28+
modelValue: PropTypes.any,
29+
formValue: PropTypes.object,
30+
fieldValue: PropTypes.object,
31+
32+
// Provided props
33+
model: PropTypes.string.isRequired,
34+
messages: PropTypes.objectOf(PropTypes.oneOfType([
35+
PropTypes.string,
36+
PropTypes.func,
37+
PropTypes.bool,
38+
])),
39+
show: PropTypes.any,
40+
wrapper: PropTypes.oneOfType([
41+
PropTypes.string,
42+
PropTypes.func,
43+
PropTypes.element,
44+
]),
45+
component: PropTypes.oneOfType([
46+
PropTypes.string,
47+
PropTypes.func,
48+
PropTypes.element,
49+
]),
50+
dispatch: PropTypes.func,
51+
dynamic: PropTypes.oneOfType([
52+
PropTypes.bool,
53+
PropTypes.arrayOf(PropTypes.string),
54+
]),
55+
};
56+
2657
function showErrors(field, form, show = true) {
2758
if (typeof show === 'function') {
2859
return show(field, form);
@@ -123,7 +154,7 @@ function createErrorsClass(s = defaultStrategy) {
123154

124155
const allowedProps = typeof wrapper === 'function'
125156
? this.props
126-
: omit(this.props, Object.keys(Errors.propTypes));
157+
: omit(this.props, Object.keys(propTypes));
127158

128159
if (!showErrors(fieldValue, formValue, show)) {
129160
return null;
@@ -142,36 +173,7 @@ function createErrorsClass(s = defaultStrategy) {
142173
}
143174
}
144175

145-
Errors.propTypes = {
146-
// Computed props
147-
modelValue: PropTypes.any,
148-
formValue: PropTypes.object,
149-
fieldValue: PropTypes.object,
150-
151-
// Provided props
152-
model: PropTypes.string.isRequired,
153-
messages: PropTypes.objectOf(PropTypes.oneOfType([
154-
PropTypes.string,
155-
PropTypes.func,
156-
PropTypes.bool,
157-
])),
158-
show: PropTypes.any,
159-
wrapper: PropTypes.oneOfType([
160-
PropTypes.string,
161-
PropTypes.func,
162-
PropTypes.element,
163-
]),
164-
component: PropTypes.oneOfType([
165-
PropTypes.string,
166-
PropTypes.func,
167-
PropTypes.element,
168-
]),
169-
dispatch: PropTypes.func,
170-
dynamic: PropTypes.oneOfType([
171-
PropTypes.bool,
172-
PropTypes.arrayOf(PropTypes.string),
173-
]),
174-
};
176+
Errors.propTypes = propTypes;
175177

176178
Errors.defaultProps = {
177179
wrapper: 'div',

0 commit comments

Comments
 (0)