I have got a layout component with an Outlet to load the child component.
Layout.tsx
import * as React from "react";
import { createTheme, styled } from "@mui/material/styles";
import Box from "@mui/material/Box";
import style from "./layout.module.scss";
import Drawer from "./Drawer";
import AppBar from "./AppBar";
import Container from "@mui/material/Container";
import Paper from "@mui/material/Paper";
import RecipeLanding from "../pages/Recipe/RecipeLanding";
import { Outlet } from "react-router-dom";
import { Typography } from "@mui/material";
export default function Layout({ children }: any) {
const [open, setOpen] = React.useState(false);
const [title,setTitle]=React.useState('');
const handleTitleUpdate=(t:string)=>{
setTitle(t);
}
return (
<ThemeContext.Provider value={Theme.background}>
<RootDiv>
<AppBar open={open} onDrawerOpen={handleDrawerOpen} />
<Drawer open={open} onDrawerClose={handleDrawerClose} />
<Container className="rootContainer" maxWidth="xl" sx={containerStyle}>
<DrawerHeader />
<Box sx={{ my: 2 }}>
<Typography variant="h5">{title}</Typography>
</Box>
<Box>
<Outlet onTitleChange={handleTitleUpdate} />
</Box>
</Container>
</RootDiv>
</ThemeContext.Provider>
);
}
It was earlier a child component directly specified instead of outlet. But since navigation is required I added an outlet and expected I can add add onTitleChange property into it. But it doesnt allow I found.
How can achieve this. So my attempt is to update the {title} in layout component when a navigation to child component happens.
Please help