#How to pass prop to a component with Link

7 messages · Page 1 of 1 (latest)

fleet hill
#

Hi all, I am trying to pass an ID string to another component. I am using NextJS 13.3.0

#

I have a link to another page and I want to pass movie.id down to it but am unsure how to do so

 <Link
                    className="bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded"
                    href={`/movies/${movie.id}`}
                  >
                    Get Recommendations
                  </Link>
#

/movies/[id].tsx

import { useRouter } from "next/router";
import * as React from "react";

interface IMovieRecommendationPageProps {}

const MovieRecommendationPage: React.FunctionComponent<
  IMovieRecommendationPageProps
> = (props) => {
  const router = useRouter();
  console.log(router)

  return <></>;
};

export default MovieRecommendationPage;

const MOVIE_API = "https://api.themoviedb.org/3";
export const getServerSideProps = async () => {
  
  
  // const res = await fetch(
  //   `${MOVIE_API}/movie/${movieID}/recommendations?api_key=${process.env.API_KEY}&language=en-US&page=1`
  // );
  // const data = await res.json();
  // return {
  //   props: {
  //     movies: data.results,
  //   },
  // };
  return{
    props: {}
  }
};
turbid halo
#

you can use context.params to get the id param from the dynamic path

fleet hill
#

Tysm

#

!closed