I am trying to pass the first: 1
through a link in react js but I am not getting it how to do it. What I have tried is below.
let first = 1;
<Link
to={{
pathname: "/sign",
state: { variable: 1 },
}}
>
<div className="box">i am pregent</div>
</Link>
<Routes>
<Route path="/sign" name="routename" element={Sign}></Route>
</Routes>
export default class Sign extends Component {
constructor(props) {
super(props);
// this.state = { variable: props.location.state.variable };
const { variable = "defaultValue" } = props.location.state
? props.location.state
: {};
console.log(variable);