I am trying to change the state through a Link component when I click on an image. I'm not sure if it's how the Link component is written or if the clickHandler
is incorrectly used, but it console logs the state as true even after I click it.
import React, {useState, useEffect} from 'react'
import {Link, Switch, Route} from 'react-router-dom'
import RecipePage from './RecipePage'
export default function Recipes({dataArray}){
const [strMeal, setStrMeal] = useState(true)
function clickHandler(){
setStrMeal(false)
}
return(
<div>
<Link to={{pathname:'/recipepage', state: {strMeal: strMeal} }}>
<div onClick={() => clickHandler()}>This is an image</div>
</Link>
</div>
)
}
How do I change the state to false?