I have a simple component that needs to pass back the link value from the child component to a function in the parent component, but it only calls back the full function and not its value. When I include "navigate(
/...)` it works but automatically goes to the page. I know im missing something super simple but its taking way too long to figure out. See below for code.
//Parent Component
function ZodiacMDates({getDate}) {
const zodiacSigns = [
{
id: 1,
asign: 'Aries',
link: 'aries',
title: 'The Aries Mars Man',
AriesSdate1: '158590800000', // '01/10/1975'
AriesEdate1: '254494800000', // '01/24/1978'
AriesSdate2: '350053200000', // '02/03/1981'
AriesEdate2: '447253200000' // '03/04/1984'
},
{
id: 2,
asign: 'Taurus',
link: 'taurus',
title: 'The Taurus Mars Man',
TaurusSdate1: '-1244372400000', // '07/27/1930'
TaurusEdate1: '-1186225200000', // '05/30/1932'
TaurusSdate2: '496501200000', // '09/25/1985'
TaurusEdate2: '521298000000' // '07/09/1986'
}
]
const clickMan = (chosenZodiac) => {
return (
chosenZodiac
)
// return (
// navigate(`/${chosenZodiac}`)
// )
}
const zodiacSignsMap = zodiacSigns.map(sign => <ZodiacMCheck
key={sign.id}
sign={sign}
getDate = {getDate}
findZodiac = {clickMan} />)
return <div>
{zodiacSignsMap}
// This button Does not work
<button onClick={()=>{navigate(`/${clickMan}`)}}>Find Me!</button>
</div>
//Child Component
function ZodiacMCheck({getDate, sign, findZodiac}) {
const zodiacLink = () => {
return (
findZodiac(sign.link)
)
}
// Check For Aries
if ((sign.AriesSdate1 <= getDate && sign.AriesEdate1 >= getDate) ||
(sign.AriesSdate2 <= getDate && sign.AriesEdate2 >= getDate ) ||
//Check For Taurus
(sign.TaurusSdate1 >= getDate && sign.TaurusEdate1 <= getDate) // Negative
|| (sign.TaurusSdate2 <= getDate && sign.TaurusEdate2 >= getDate )) {
let zodiacSign = zodiacLink();
return (
<div>
{zodiacsign}
</div>
)
}
else {
return (null)
}
}
export default ZodiacMCheck