I have a QR code application that scans qr codes and it works. I want to add a redirection operation after the scanning has successfuly taken place.
Here is my code
import React, {Component} from "react";
import ReactDOM from 'react-dom';
import { Redirect } from "react-router-dom";
import BarcodeScannerComponent from "react-qr-barcode-scanner";
class QR extends Component {
constructor(props) {
super(props);
this.state = {
data: "Not Found"
};
}
render() {
return (
<>
<BarcodeScannerComponent
width={500}
height={500}
onUpdate={(err, result) => {
if (result) {
this.setState({data: result.text});
return <Redirect to={this.state.data} />
}
else this.setState({data: "Not Found"});
}}
/>
<p>{this.state.data}</p>
</>
);
}
}
ReactDOM.render(
<QR />,
document.getElementById('qr-id')
);
Although after successful scanning has taken place, no redirect occurs. Can somebody point out a good way of doing redirects in react?
{this.state.data}
)} ``` – Áron Pop Adorján Aug 03 '21 at 08:14