« first day (4425 days earlier)      last day (516 days later) » 

8:46 AM
@1.21gigawatts this is my code for year filtering
  const yearClickHandler = useCallback(
    (year: number) => {
      const _selectedYears = [...selectedYears]

      _selectedYears.includes(year)
        ? _selectedYears.splice(_selectedYears.indexOf(year), 1)
        : _selectedYears.push(year)

      setSelectedYears(_selectedYears)

      // eslint-disable-next-line  @typescript-eslint/no-explicit-any
      const filter = (_rowData: any[]): any[] => {
        // eslint-disable-next-line  @typescript-eslint/no-explicit-any
        let filtered: any = []
I can see that newly filtered array in console log, but it's not displayed on UI
@OlegValteriswithUkraine
What's wrong with this code ?
also this one
export const TableYearFilter = ({ rowData, filterCallback }: YearsProps) => {
  const bookingYears = useMemo(() => {
    const years = [
      ...new Set(
        rowData?.map((row) => {
          return row.booking_date[0]
        }),
      ),
    ]
    return years
  }, [rowData])

  const [selectedYears, setSelectedYears] = useState(bookingYears)
but very strange is this code is the fact that I receiving booking_date as string instead of array of strings, but this code works

const years = [
      ...new Set(
        rowData?.map((row) => {
          return row.booking_date[0]
        }),
      ),
    ]
 
9:02 AM
@1.21gigawatts it's not reproducible like this, but maybe you have idea ?
it's very very strange
 
 
3 hours later…
11:49 AM
@MileMijatović Can you share your end-to-end use case so we can see if we could modify/write a new code for your use case.
 
@somesh Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
12:16 PM
Unfortunately can't, it's complex
 
 
4 hours later…
3:56 PM
export const TableYearFilter = ({ rowData, filterCallback }: YearsProps) => {
  const bookingYears = useMemo(() => {
    const years = [
      ...new Set(
        rowData?.map((row) => {
          const bookingDate = row?.booking_date
          return Number(bookingDate.slice(bookingDate.lastIndexOf('.') + 1))
        }),
      ),
    ]
    return years
  }, [rowData])

  const [selectedYears, setSelectedYears] = useState(bookingYears)
useMemo and useState are async hooks
and of course this does not work
bookingYears state is [NaN]
What's the proper way to use useMemo with useState ?
 
 
1 hour later…
5:17 PM
"I am an idiot" moment of the day: what do you think is wrong with for (const row of body.rows) row.remove(); (assuming body is a TableSectionElement)?
 
 
6 hours later…
11:14 PM
@MileMijatović i would recommend to not use the new array features
and see if that works
instead of using forEach use for loop
forEach() expects a synchronous function — it does not wait for promises. Make sure you are aware of the implications while using promises (or async functions) as forEach callbacks.
*I would recommend to not use the new array features as a test to see if that's causing the issues
personally i choose not to use them because I had to convert a synchronous function to an async and i started getting errors because the callbacks were called after i needed them
forEach()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
maybe also try to replace map
 

« first day (4425 days earlier)      last day (516 days later) »