TanStackT
TanStack3y ago
1 reply
moderate-tomato

TypeError: data.some is not a function

I'm trying to create a simple chart based on some data I get from an API, but I get the following error: TypeError: data.some is not a function.
But I'm not to sure what the cause of this issue is?


type PointsData = {
    speed: number,
    distance: number,
}

type Series = {
    label: string,
    data: PointsData[]
}


export const LineChart = ({ data }: { data: Activity }) => {

    const Chart = dynamic(() => import("react-charts").then(mod => mod.Chart), { ssr: false })

    const chartData: Series = {
        label: "Test",
        data: data?.records?.map(e => ({
            speed: e?.Speed,
            distance: e?.Distance
        }))
    }

    const primaryAxis = React.useMemo(
        (): AxisOptions<PointsData> => ({
            getValue: datum => datum?.speed,
        }),
        []
    )

    const secondaryAxes = React.useMemo(
        (): AxisOptions<PointsData>[] => [
            {
                getValue: datum => datum?.distance,
            },
        ],
        []
    )

    return (
        <>
            {
                chartData && chartData?.data.length && primaryAxis && secondaryAxes && (<ResizableBox>
                    <Chart
                        options={{
                            data: chartData,
                            primaryAxis,
                            secondaryAxes,
                        }}
                    />
                </ResizableBox>
                )
            }
        </>
    );
}
Was this page helpful?