TripReviewSection\hooks\useTripReviewFilter.js

mail@pastecode.io avatar
unknown
typescript
8 days ago
966 B
0
Indexable
Never
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'

function useTripReviewFilter() {
  const dispatch = useDispatch()
  const { selectedCompanyId } = useSelector(state => state.companyData)
  const { latestDate } = useSelector(state => state.portalData)
  const [users, setUsers] = useState([])
  const [trainIds, setTrainIds] = useState([])
  const [crewIds, setCrewIds] = useState([])
  const [locoIds, setLocoIds] = useState([])

  useEffect(() => {
    const fetchFilterData = async () => {
      setUsers(users.payload)
      setTrainIds(trainIds.payload)
      setCrewIds(crewIds.payload)
      setLocoIds(locoIds.payload)
    }
    fetchFilterData()
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])
  return {
    latestDate: latestDate.data,
    selectedCompanyId,
    users,
    trainIds,
    crewIds,
    locoIds
  }
}

export default useTripReviewFilter
Leave a Comment