refactor: destructure loaderData in multiple components for cleaner code

This commit is contained in:
Ardeman
2025-03-09 09:32:51 +08:00
parent 09e5f84b8b
commit 0da2006e78
20 changed files with 34 additions and 42 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ export const CategoriesPage = () => {
const loaderData = useRouteLoaderData<typeof loader>(
'routes/_admin.lg-admin._dashboard.categories._index',
)
const categoriesData = loaderData?.dataCategories
const { dataCategories: categoriesData } = loaderData || {}
DataTable.use(DT)
const dataTable = categoriesData?.sort((a, b) => {
+1 -1
View File
@@ -15,7 +15,7 @@ export const ContentsPage = () => {
const loaderData = useRouteLoaderData<typeof loader>(
'routes/_admin.lg-admin._dashboard.contents._index',
)
const newsData = loaderData?.newsData
const { newsData } = loaderData || {}
DataTable.use(DT)
const dataTable = newsData?.sort(
+1 -2
View File
@@ -11,8 +11,7 @@ export const TagsPage = () => {
const loaderData = useRouteLoaderData<typeof loader>(
'routes/_admin.lg-admin._dashboard.tags._index',
)
const tagsData = loaderData?.tagsData
const dataTable = tagsData
const { tagsData: dataTable } = loaderData || {}
DataTable.use(DT)
const dataColumns = [
+2 -2
View File
@@ -65,8 +65,8 @@ export const FormContentsPage = (properties: TProperties) => {
const fetcher = useFetcher()
const navigate = useNavigate()
const loaderData = useRouteLoaderData<typeof loader>('routes/_admin.lg-admin')
const categories = loaderData?.categoriesData
const tags = loaderData?.tagsData
const { categoriesData: categories } = loaderData || {}
const { tagsData: tags } = loaderData || {}
const [error, setError] = useState<string>()
const [disabled, setDisabled] = useState(false)
+1 -2
View File
@@ -15,9 +15,8 @@ export const NewsDetailPage = () => {
'routes/_news.detail.$slug',
)
const currentUrl = globalThis.location
const { newsDetailData } = loaderData || {}
const { title, content, featured_image, author, live_at, tags } =
newsDetailData || {}
loaderData?.newsDetailData || {}
const { text } = useReadingTime(content || '')