轻松聘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.4 KiB

/**
* 岗位列表数据 hook(排序/筛选/搜索/分页均在接口层 fetchJobList 完成)
*/
import { useCallback, useMemo } from 'react';
import { fetchJobList } from '../api';
import type { Job, JobListParams } from '../types';
import { useAsyncData } from './useAsyncData';
export function useJobList(params?: Partial<JobListParams>) {
const sortBy = params?.sortBy ?? 'comprehensive';
const keyword = params?.keyword;
const industry = params?.industry;
const city = params?.city;
const salary = params?.salary;
const experience = params?.experience;
const education = params?.education;
const page = params?.page;
const pageSize = params?.pageSize;
// fetcher 引用需稳定:以基础类型为依赖,避免 useAsyncData 反复触发
const fetcher = useCallback(
() =>
fetchJobList({
sortBy,
keyword,
industry,
city,
salary,
experience,
education,
page,
pageSize,
}),
[sortBy, keyword, industry, city, salary, experience, education, page, pageSize],
);
const { data, loading, error, refresh } = useAsyncData(fetcher);
const jobs = useMemo<Job[]>(() => data?.jobs ?? [], [data]);
const total = data?.total ?? 0;
// 空状态:加载完成且无错误、但列表为空
const isEmpty = !loading && !error && jobs.length === 0;
return { jobs, total, loading, error, refresh, isEmpty };
}