Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function fetchData() {
try {
const nextIdentity = await fetchIdentity()
if (!deepEqual(identity, nextIdentity)) {
const state =
identity &&
identity.state === IdentityStatus.Terminating &&
nextIdentity &&
nextIdentity.state !== IdentityStatus.Undefined // still mining
? identity.state
: nextIdentity.state
setIdentity({...nextIdentity, state})
}
} catch (error) {
global.logger.error(
'An error occured while fetching identity',
error.message
)
}
}
const submit = useCallback(() => {
const cleanData = {
...data,
text: data.text.trim(),
};
if (!cleanData.text) {
textField.current.ref.current.select();
return;
}
if (!dequal(cleanData, defaultData)) {
onUpdate(cleanData);
}
close();
}, [defaultData, onUpdate, data, close]);
function useDeepCompareCallback(callback, deps) {
const ref = React.useRef()
if (!deepEqual(deps, ref.current)) {
ref.current = deps
}
return React.useCallback(callback, ref.current)
}
const handleSubmit = useCallback(() => {
const cleanData = {
...data,
name: data.name.trim() || null,
};
if (!dequal(cleanData, defaultData)) {
onUpdate(cleanData);
}
onBack();
}, [defaultData, data, onUpdate, onBack]);
static getDerivedStateFromProps(props, state) {
const subtitles = props.subtitles.filter(item => {
return (
(item.startTime >= props.beginTime && item.startTime <= props.beginTime + 10) ||
(item.endTime >= props.beginTime && item.endTime <= props.beginTime + 10)
);
});
return dequal(subtitles, state.subtitles)
? null
: {
subtitles,
};
}
hoursField.current.select();
return;
}
if (Number.isNaN(parts.minutes) || parts.minutes > 60) {
minutesField.current.select();
return;
}
if (Number.isNaN(parts.seconds) || parts.seconds > 60) {
secondsField.current.select();
return;
}
if (defaultValue) {
if (!dequal(parts, getTimerParts(defaultValue))) {
onUpdate(updateTimer(defaultValue, parts));
}
} else {
onUpdate(createTimer(parts));
}
onClose();
}, [defaultValue, onUpdate, onClose, data]);
useInterval(async () => {
try {
const nextEpoch = await fetchEpoch()
if (!deepEqual(epoch, nextEpoch)) {
setEpoch(nextEpoch)
}
} catch (error) {
global.logger.error(
'An error occured while fetching epoch',
error.message
)
}
}, interval)
function useDeepCompareMemoize(value) {
const ref = React.useRef()
if (!deepEqual(value, ref.current)) {
ref.current = value
}
return ref.current
}
const handleSubmit = useCallback(() => {
const cleanData = {
...data,
name: data.name.trim(),
};
if (!cleanData.name) {
nameField.current.select();
return;
}
if (!dequal(cleanData, defaultData)) {
onUpdate(cleanData);
}
onClose();
}, [defaultData, onUpdate, onClose, data]);