Skip to content

Commit

Permalink
fix(react): pre-defined defaults to prevent infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Allen committed Feb 20, 2025
1 parent f0aef3a commit 824086b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example/src/formSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"::placeholder": {
"color": "orange"
},
":placeholder-shown": {
":placeholderShown": {
"background": "orange"
}
}
Expand Down
45 changes: 27 additions & 18 deletions src/FormBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,43 @@ const debugLog = (...args) => {
if (debug) console.log(...args) //eslint-disable-line
}

const defaults = {
object: {},
map: Map(),
nullFunction: () => null,
dropItemDimensions: {
h: 1,
w: 6
},
dropItemConfig: {
name: 'new-input',
label: 'New Field',
type: 'input'
},
device: {cordova: false, model: 'browser', platform: 'browser', uuid: 'browser', version: 'browser'}
}

const FormBuilder = (props) => {
const {
rowHeight,
columns = 12,
formSchema = {},
formSchema = defaults.object,
width,
handleOnDimensionChange,
dropItemDimensions = {
h: 1,
w: 6
},
dropItemConfig = {
name: 'new-input',
label: 'New Field',
type: 'input'
},
dropItemDimensions = defaults.dropItemDimensions,
dropItemConfig = defaults.dropItemConfig,
validate,
requiredFlag,
setContainerRef,
onClick = () => null,
handleOnDrop = () => null,
handleCascade = () => null,
handleRTEImageClick: onRTEImageClick = () => null,
handleLinkClick = () => null,
onClick = defaults.nullFunction,
handleOnDrop = defaults.nullFunction,
handleCascade = defaults.nullFunction,
handleRTEImageClick: onRTEImageClick = defaults.nullFunction,
handleLinkClick = defaults.nullFunction,
conditionalFieldValues,
conditionalSearch,
inline,
handleOnChange = () => null,
handleOnChange = defaults.nullFunction,
interactive = true,
draggable = false,
readonly,
Expand All @@ -62,8 +71,8 @@ const FormBuilder = (props) => {
timeFormat = 'h:mm a',
autoComplete = 'ac_off',
style = {},
device = {cordova: false, model: 'browser', platform: 'browser', uuid: 'browser', version: 'browser'},
fieldDefinitions = Map(),
device = defaults.device,
fieldDefinitions = defaults.map,
c2class
} = props
const [grid, updateGrid] = useState({layout: [], elements: []})
Expand Down
14 changes: 13 additions & 1 deletion src/Inputs/ConditionalInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ import PropTypes from 'prop-types'
import ConditionalDialog from './ConditionalDialog'
import {Map, List, fromJS} from 'immutable'

const defaults = {
object: {},
map: Map(),
nullFunction: () => null
}

const ConditionalInput = props => {
const {style = {}, name = '', value = Map(), values = Map(), onChange = () => null} = props
const {
style = defaults.object,
name = '',
value = defaults.map,
values = defaults.map,
onChange = defaults.nullFunction
} = props

const {value: valueStyle = {}, inputOuter = {}, inputInner = {}, inputControl = {}, valueContainer = {}, indicators = {}} = style// eslint-disable-line

Expand Down
6 changes: 5 additions & 1 deletion src/Inputs/Date/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {randomId} from '../../utils'
import ValidationErrorIcon from '../../ValidationErrorIcon'
import useTheme from '../../theme/useTheme'

const defaults = {
trueFunction: () => true
}

const DateInput = props => {
const {
name,
Expand Down Expand Up @@ -37,7 +41,7 @@ const DateInput = props => {
futureYears = 12,
minDate,
maxDate,
onChangeValidator = () => true,
onChangeValidator = defaults.trueFunction,
warning
} = props

Expand Down
11 changes: 8 additions & 3 deletions src/Inputs/Typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class TypeaheadPerformanceOptimizer extends PureComponent {
}
}

const defaults = {
nullFunction: () => null,
object: {}
}

const Typeahead = props => {
const {
name,
Expand All @@ -142,10 +147,10 @@ const Typeahead = props => {
requiredWarning,
required,
tabIndex,
onKeyDown = () => null,
onKeyDown = defaults.nullFunction,
draggable,
persist = true,
typeahead = {},
typeahead = defaults.object,
minChars = 1,
stringify,
autoComplete,
Expand All @@ -155,7 +160,7 @@ const Typeahead = props => {
delimiter,
isClearable = true,
createlabel,
options: typeaheadOptions = {},
options: typeaheadOptions = defaults.object,
warning
} = props

Expand Down

0 comments on commit 824086b

Please sign in to comment.