How can I prevent the freeze when running this code? Does async/await can be use as a solution? The data has 18MB size so it freeze somehow.
The Validation have many cases to pass through and the data consist of 125k test case. How can I possibly prevent the freeze?
const getEachValueByLine = useCallback(
() => {
if (IsJsonString(multipleValue)) {
setInvalidFormat(true)
isValidRegex ? setValidRegex(true) : setValidRegex(false)
const parseValue = Object.entries(JSON.parse(multipleValue))
const addId = parseValue.map((item, index) => ({ id: index, case: item[0], expected: item[1] }))
handleMultiValidate(addId)
} else {
setInvalidFormat(false)
}
},
[handleMultiValidate, multipleValue],
)
const handleMultiValidate = (data) => {
const validateArr = []
if (data.length > 0) {
data.forEach((value) => {
if (validRegex && customRegex !== '') {
validateArr.push({
type: multiValidateBy,
data: value.case,
acceptType: [
],
isDecimal: isDecimal,
isCustomRegex: isCustomRegex,
localisedRegexCode: localisedRegexCode,
customRegex: validRegex ? customRegex : ''
})
} else {
validateArr.push({
type: multiValidateBy,
data: value.case,
acceptType: [
],
isDecimal: isDecimal,
isCustomRegex: isCustomRegex,
localisedRegexCode: localisedRegexCode
})
}
})
const result = validator(validateArr)
result['data'].map((res, i) => {
if (res.data === data[i].case) {
res.expected = data[i].expected
}
return res
})
setMultiResult(result)
} else {
setMultiResult({
status: true
})
}
}