0

I have lots of nested components in my next.js application.

And for getting translations i rely on the params.lang.

Now i have drill this to every single component.

I know there are hooks, but i want to render them as server components.

Is there any workaround to avoid prop drilling and get access to params.lang inside NESTED server components?

import { getDictionary } from "@/get-dictionary";
import React from "react";

type Props = {
  link: string;
};

const ShareButton = (props: Props) => {

    // something here to get the params.lang without relying on props?
    const locale = ? 

    const dictionary = await getDictionary(locale)

  return <div>ShareButton</div>;
};

export default ShareButton;

Shreyas Jadhav
  • 2,363
  • 4
  • 10
  • 23

1 Answers1

0

You can store the params in cookies which can easily acess from anywhere by importing

import { cookies } from "next/headers"

Reference : Docs

Kannu Mandora
  • 479
  • 2
  • 10