refactor: convert all class components to function components (#431)#444
Open
nahrinoda wants to merge 9 commits into
Open
refactor: convert all class components to function components (#431)#444nahrinoda wants to merge 9 commits into
nahrinoda wants to merge 9 commits into
Conversation
…sk#431) Convert ExpandIcon from React.PureComponent class to a function component wrapped with React.memo to preserve shallow prop comparison behavior. - Replace static defaultProps with JS default parameters - Replace constructor bind with useCallback hook - Move propTypes to a static property on the function component - No behavioral changes Resolves part of Autodesk#431 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…odesk#431) Convert ColumnResizer from React.PureComponent class to a function component wrapped with React.memo. - Replace instance variables with useRef for mutable drag state (isDragging, lastX, width, handleRef) - Use refs for props accessed in DOM event listeners (column, onResize, onResizeStop, minWidth) to avoid stale closures - Replace constructor binds with useCallback hooks - Replace componentWillUnmount with useEffect cleanup - Replace static defaultProps with JS default parameters - Move propTypes to a property on the function component - No behavioral changes Resolves part of Autodesk#431 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#431) Convert TableRow from React.PureComponent class to a function component wrapped with React.memo. - Replace this.state { measured } with useState hook - Replace this.ref with useRef hook - Replace componentDidMount with useEffect for initial measurement - Replace componentDidUpdate re-measure cycle with two useEffect hooks: one to detect when re-measurement is needed, one to trigger it - Replace _getEventHandlers with useMemo - Replace _handleExpand with useCallback - Replace static defaultProps with JS default parameters - Move propTypes to a property on the function component - No behavioral changes Resolves part of Autodesk#431 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…esk#431) Convert TableHeader from React.PureComponent class to a function component using forwardRef + useImperativeHandle + React.memo. - Use forwardRef to expose imperative scrollTo() and forceUpdate() methods - Replace this.headerRef with useRef hook - Replace constructor-bound render methods with useCallback hooks - Use useReducer to implement forceUpdate behavior - Update GridTable header ref type to TableHeaderHandle - No behavioral changes Resolves part of Autodesk#431 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…k#431) - Replace class with forwardRef + React.memo function component - Convert instance methods to useImperativeHandle (resetAfterRowIndex, forceUpdateTable, scrollToPosition, scrollToTop, scrollToLeft, scrollToRow, getTotalRowsHeight) - Convert memoized helpers to useMemo/useCallback hooks - Update BaseTable ref types to use GridTableHandle interface Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace class with function component returning null - Move static properties (Alignment, FrozenDirection) to direct assignments Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…k#431) - Replace class with forwardRef + React.memo function component - Convert state to useState hooks (scrollbarSize, hoveredRowKey, resizingKey, resizingWidth, expandedRowKeys) - Convert instance variables to useRef (scroll position, row height maps, scrollbar sizes, data tracking, column manager) - Convert memoized helpers to useMemo with memoize-one - Convert throttled column resize handler to stable useMemo callback - Convert debounced row height update to stable useMemo callback - Convert lifecycle methods to useEffect hooks - Expose public API via useImperativeHandle (getDOMNode, getColumnManager, scroll methods, expand methods, etc.) - Add BaseTableHandle interface for imperative ref type - Maintain static properties (Column, PlaceholderKey) on memo wrapper Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move all component prop interfaces and handle types from individual component files into the central src/types.ts - Components now import their types from types.ts instead of defining them locally - Re-export all type definitions from index.ts for consumer access - No behavioral changes — only import paths changed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove PropTypes from all 12 component files (TypeScript interfaces supersede them) - Disable ESLint react/prop-types rule - Replace [key: string]: any with React.HTMLAttributes<HTMLDivElement> in ColumnResizerProps, ExpandIconProps, and SortIndicatorProps - Add explanatory comments for remaining index signatures in pass-through components - Remove prop-types import from all source files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts all 7 class components to function components with React hooks, consolidates all TypeScript type definitions into a single
types.tsfile, removes PropTypes in favor of TypeScript, and improves type safety — fully resolving #431.Components converted
React.memo,useCallback, JS default paramsuseReffor drag state, ref-based prop access for DOM listeners to avoid stale closures,useEffectcleanupuseState,useRef,useMemo, splitcomponentDidUpdateinto multipleuseEffecthooks for re-measurement cycleforwardRef+useImperativeHandle(scrollTo,forceUpdate),useReducerfor force-update trickforwardRef+useImperativeHandle(7 imperative methods),useMemowithmemoize-onenullwith static property assignmentsuseState(5 state vars), 17+useRefinstances,useMemofor memoized helpers,throttle/debouncewith stable identity viauseMemo,forwardRef+useImperativeHandle(14 public API methods),useEffectfor lifecycleMigration patterns
React.PureComponent->React.memowrapperstatic defaultProps-> JS default parameters in destructuring.bind(this)->useCallbackhooksuseRefthis.state/setState->useStatecomponentDidMount/componentDidUpdate->useEffectcomponentWillUnmount->useEffectcleanup returnforceUpdate()->useReducercounter trickforwardRef+useImperativeHandlememoize-onecalls ->useMemo(() => memoize(...), [])useMemowith stable identity +useReffor latest propsType consolidation
Moved all 14 component prop interfaces and handle types from individual component files into the central
src/types.ts, joining the 15 types already there. All types are re-exported fromindex.tsfor consumer access.AutoResizerPropsAutoResizer.tsxBaseTableProps,BaseTableHandleBaseTable.tsxColumnResizerPropsColumnResizer.tsxExpandIconPropsExpandIcon.tsxGridTableProps,GridTableHandleGridTable.tsxSortIndicatorPropsSortIndicator.tsxTableCellPropsTableCell.tsxTableHeaderProps,TableHeaderHandleTableHeader.tsxTableHeaderCellPropsTableHeaderCell.tsxTableHeaderRowPropsTableHeaderRow.tsxTableRowPropsTableRow.tsxBest practices applied
PropTypes removal — Removed PropTypes from all 12 component files (~520 lines deleted). TypeScript interfaces in
types.tsfully supersede runtime prop validation. The ESLintreact/prop-typesrule is now disabled. PropTypes are removed from the React 19 package entirely.Type safety improvements — Replaced loose
[key: string]: anyindex signatures withReact.HTMLAttributes<HTMLDivElement>inColumnResizerProps,ExpandIconProps, andSortIndicatorProps. Remaining index signatures are documented with comments explaining they exist for legitimate pass-through patterns (e.g., GridTable forwarding props to react-window Grid, or row/header components spreading props to configurable tag elements).Future migration paths
forwardRef deprecation (React 19) —
forwardRefis deprecated in React 19;refbecomes a regular prop. Components usingforwardRef(BaseTable, GridTable, TableHeader) can be simplified when upgrading. No action needed now.React Compiler readiness — The React Compiler (v1.0, Oct 2025) auto-memoizes components, eliminating the need for
React.memo,useCallback, anduseMemo. The current code is compatible — these wrappers can be safely removed when adopting the compiler.What is NOT changed
import typeusage is correct throughout (verified via audit)Test plan
tsc --emitDeclarationOnly) passes with zero errorsScreen.Recording.2026-06-19.at.4.39.19.PM.mov
Resolves #431