Skip to content

Commit

Permalink
Small updates to the TypeScript types (#65)
Browse files Browse the repository at this point in the history
* Allow `childrenAccessor` function to return `null`
* Express that this component won't change the `data` you pass it
  • Loading branch information
nvie authored Nov 17, 2022
1 parent 86b61e7 commit cc941da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react-arborist/src/data/create-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function createRoot<T>(tree: TreeApi<T>): NodeApi<T> {
rowIndex: null,
});

const data: T[] = tree.props.data ?? [];
const data: readonly T[] = tree.props.data ?? [];

root.children = data.map((child) => {
return visitSelfAndChildren(child, 0, root);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-arborist/src/hooks/use-simple-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type SimpleTreeData = {

let nextId = 0;

export function useSimpleTree<T>(initialData: T[]) {
export function useSimpleTree<T>(initialData: readonly T[]) {
const [data, setData] = useState(initialData);
const tree = useMemo(
() =>
Expand Down
6 changes: 3 additions & 3 deletions packages/react-arborist/src/types/tree-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { OpenMap, OpenSlice } from "../state/open-slice";

export interface TreeProps<T> {
/* Data Options */
data?: T[];
initialData?: T[];
data?: readonly T[];
initialData?: readonly T[];

/* Data Handlers */
onCreate?: handlers.CreateHandler<T>;
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface TreeProps<T> {
selectionFollowsFocus?: boolean;
disableDrag?: string | boolean | BoolFunc<T>;
disableDrop?: string | boolean | BoolFunc<T>;
childrenAccessor?: string | ((d: T) => T[]);
childrenAccessor?: string | ((d: T) => T[] | null);
idAccessor?: string | ((d: T) => string);

/* Event Handlers */
Expand Down

0 comments on commit cc941da

Please sign in to comment.