const { themes: { all, selectedId } } = useLoaderData<typeof loader>();
(property) themes: JsonifyObject<{
all: Theme[];
selectedId: string;
}>
const all: Body[]
import { useLoaderData } from 'react-router-dom'
type LoaderProps = {
themes: {
all: string[],
selectedId: string
}
} | null
export const Component = () => {
const data = useLoaderData() as LoaderProps
return data?.themes ? (
<>
Selected theme Id: { data.themes.selectedId }
All themes: { JSON.stringify(data.themes.all) }
</>
) : (
<>No themes</>
)
}
///
export const routes = [
{
path: '/',
element: <Component/>,
loader: () => ({
themes: {
all: [
'light',
'dark'
],
selectedId: 'light'
}
})
}
/* ... */
]