NextJS get state from layout to children

Viewed 21

I have a cart component in my navbar and is on the layout.js I want to pass it to the children

export default function Layout({ children }) {
  const [cart, setItems] = useState([]);

  return (
    <ChakraProvider theme={addTheme}>
      <Navbar cart={cart} />
      {children}
      <Footer />
    </ChakraProvider>
  );
}

Is there any way to pass the state cart state to the {children} or pass it to the current page?

0 Answers
Related