lukasbach/react-complex-tree

Expose treeItem internals

keegan-lillo opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
I've been creating a solution to #263 for my own usage and I managed to get something that works pretty well using a few custom renderers, however I have had to reach into the lib directory and import TreeItem.

import { TreeItem } from 'react-complex-tree/lib/cjs/treeItem/TreeItem'

This isn't a huge issue, however I have had to also update all my other imports to use 'react-complex-tree/lib/cjs' since NextJS/Webpack switches between the CJS and ESM versions depending on client/server builds so React context gets lost.

Describe the solution you'd like
Expose TreeItem or useTreeItemRenderContext to the main package. If they are still "unstable", maybe expose them under a __UNSTABLE constant?

// src/index.ts
import { useTreeItemRenderContext } from './treeItem/useTreeItemRenderContext';
import { TreeItem } from './treeItem/TreeItem';

export * from './controlledEnvironment/ControlledTreeEnvironment';
export * from './tree/Tree';
export * from './uncontrolledEnvironment/UncontrolledTreeEnvironment';
export * from './uncontrolledEnvironment/StaticTreeDataProvider';
export * from './types';
export * from './renderers';

export const __UNSTABLE = {
  useTreeItemRenderContext,
  TreeItem,
};

Describe alternatives you've considered

  • Import directly from 'react-complex-tree/lib/cjs'

Additional context

Hey, thanks for the suggestion. The TreeItem component isn't actually that unstable, but I'd still consider it an implementation detail that doesn't make sense to expose directly. But I did expose it as part of a "INTERNALS" export that I added now in v2.3.3, similar to what you suggested. Note that I renamed TreeItem to TreeItemElement to avoid confusion with the type of the same name TreeItem, which refers to the data field.

For the hook you mentioned, I can actually see realistic use cases for that and it makes more sense to use in normal applications, so I exposed the hook also in v2.3.3 as normal export.