cschroeter / park-ui

Beautifully designed components built on Ark UI that work for the JS and CSS frameworks of your choice.
https://park-ui.com
MIT License
1.47k stars 59 forks source link

Tree View: TypeError: selectedIds.includes is not a function #321

Open Lamonin opened 1 month ago

Lamonin commented 1 month ago

Maybe I don't understand something, but I've already spent 10 hours looking for an error on my part, however without success. So I assume that the error is inside the TreeView component.

When I try to change TreeViewData, I get the following error: image

There is also another error popping up in the console: image

Code of my component:

const DisciplineTree: FC<DisciplineTreeProps> = ({ treeType = TreeType.CourseStructure }) => {
    const { data, mutate } = useSWR<Discipline>("api/disciplines/1/sections", jsonFetcher, {
        keepPreviousData: true,
        revalidateOnFocus: false,
    });

    const updateData = useCallback(() => {
        mutate();
    }, [mutate]);

    const treeViewData = useMemo(() => {
        return {
            label: "Discipline Tree",
            children: data ? displaySections(data.sections, treeType, updateData) : [],
        };
    }, [data, treeType, updateData]);

    return <TreeView data={treeViewData} />;
};

displaySections just converts my data into an array of Child to then pass it all to the TreeView.

treeViewData is created absolutely correctly. If instead of TreeView I display just a list, for example, via ul and li, then when I try to update the data via updateData (via mutate) everything will work.

Maybe that's important, too. I also pass several such components inside Child, so that when you click on them, some kind of data processing happens.

<TreeItemButton
    key="delete-section"
    icon={Trash2}
    onClick={async () => {
        await deleteSection(section.id);
        updateData();
    }}
    hoverColor="red"
/>