Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onBarCodeRead = ({ data }: { data: string }) => {
if (data && data !== this.lastData && !this.completed) {
this.lastData = data;
try {
this.frames = parseFramesReducer(this.frames, data);
this.setState({ progress: progressOfFrames(this.frames) });
if (areFramesComplete(this.frames)) {
try {
this.onResult(decode(framesToData(this.frames).toString()));
this.completed = true;
} catch (error) {
this.frames = null;
this.setState({ error, progress: 0 });
}
}
} catch (e) {
console.warn(e);
}
}
};
componentDidMount() {
const { navigation } = this.props;
const data = navigation.getParam("data");
if (data) {
const frames = data.reduce(parseFramesReducer, null);
if (areFramesComplete(frames)) {
this.onResult(decode(framesToData(frames).toString()));
}
}
}