I want to pass my URL as props so I can use it in my Link tag( to redirect to another page).
I am not sure what I’m doing wrong.
My code:
import React, {createContext} from 'react'
import game1 from '../imgs/goldenjackpot.png'
import game2 from '../imgs/findtheball1.jpg'
export const GamesContext = createContext();
const GamesContextProvider = (props) => {
const games = [
{url: www.example.com , id: 1, image: game1, title: 'golden jackpot', price: 1000.00, category: 1, isNew: true, topPrize: "N5,000,000", isVerOrient: true,
desc: "Scratch only 4 cards, if you find the jackpot card, you win N5,000,000. If you match 4 identical cards you win N50,000 instantly!"},
{url: www.example.com , id: 2, image: game2, title: 'find the ball', price: 1000.00, category: 2, isNew: true, topPrize: "N50,000", isVerOrient: false,
desc: "Scratch only 1 box to reveal the ball, if you find the ball, you win N50,000 instantly!"},
]
return (
<GamesContext.Provider value={{ games }}>
{ props.children }
</GamesContext.Provider>
);
}
export default GamesContextProvider;
Here is the file I want to access the props
import React from 'react'
import { FiShoppingCart } from "react-icons/fi"
import { Tooltip} from '@trendmicro/react-tooltip';
import { Link } from 'react-router-dom'
import GameTag from './GameTag';
const GameBox = (props) => {
const gameImage = 'url('+props.image+')'
return (
<div>
// Am I doing it right here?
<Link to={ props.url} key={props.id} className="game-box">
<div className="image flex justify-center">
<span className="img-box" style={{ background: gameImage, backgroundSize: 'cover', backgroundRepeat: 'no-repeat' }}></span>
</div>
<div className="content flex justify-between">
<div className="text">
<h1>{props.title}</h1>
<span>₦{props.price.toLocaleString()}</span>
</div>
<div className="cta flex justify-center">
<Tooltip placement="top" content="Add To Cart">
<FiShoppingCart />
</Tooltip>
</div>
</div>
{ props.isNew&& ( <GameTag text="new" placement="top-left" /> )}
{/* <div className="flex winning-price">
<span>top prize: ₦50,000</span>
</div> */}
</Link>
</div>
);
}
export default GameBox;
Any help would be very much appreciated. Thank you in advance