Skip to content

Conversation

@AnnMarieW
Copy link
Collaborator

Closed #390

This fixes the console error about defaultProps being removed in React 19

@KoolADE85
Copy link
Contributor

Hey @AnnMarieW thanks for this! It's working great on my end! Any reason to keep it in draft? I'm happy to do a v33 release that includes this.

@BSd3v
Copy link
Collaborator

BSd3v commented Jul 25, 2025

Could we do something like what you are doing with the persistence:

import { pick } from 'ramda';

// Register all community features
ModuleRegistry.registerModules([AllCommunityModule]);

const RealAgGrid = lazy(LazyLoader.agGrid);
const RealAgGridEnterprise = lazy(LazyLoader.agGridEnterprise);

function getGrid(enable) {
    return enable ? RealAgGridEnterprise : RealAgGrid;
}

export const defaultProps = {
    className: '',
    resetColumnState: false,
    exportDataAsCsv: false,
    selectAll: false,
    deselectAll: false,
    enableEnterpriseModules: false,
    updateColumnState: false,
    persisted_props: ['selectedRows'],
    persistence_type: 'local',
    suppressDragLeaveHidesColumns: true,
    dangerously_allow_code: false,
    rowModelType: 'clientSide',
    dashGridOptions: {},
    filterModel: {},
    paginationGoTo: null,
    selectedRows: [],
};

/**
 * Dash interface to AG Grid, a powerful tabular data component.
 */
function DashAgGrid(props) {
    const [state, setState] = useState({
        mounted: false,
        rowTransaction: null,
    });

    const buildArray = useCallback((arr1, arr2) => {
        if (arr1) {
            if (!arr1.includes(arr2)) {
                return [...arr1, arr2];
            }
            return arr1;
        }
        return [JSON.parse(JSON.stringify(arr2))];
    }, []);

    useEffect(() => {
        if (props.rowTransaction && !state.mounted) {
            setState((prevState) => ({
                ...prevState,
                rowTransaction: buildArray(
                    prevState.rowTransaction,
                    props.rowTransaction
                ),
            }));
        }
    }, [props.rowTransaction, state.mounted, buildArray]);

    const {enableEnterpriseModules} = props;
    const RealComponent = getGrid(enableEnterpriseModules);

    return (
        <Suspense fallback={null}>
            <RealComponent parentState={state} {...defaultProps} {...props} />
        </Suspense>
    );
}

const REACT_VERSION_DASH2_COMPAT = 18.3;
if (
 parseFloat(React.version.substring(0, React.version.lastIndexOf('.'))) >
    REACT_VERSION_DASH2_COMPAT
) {
    DashAgGrid.defaultProps = defaultProps;
} else {
    DashAgGrid.dashPersistence = pick(['persisted_props', 'persistence_type'],defaultProps);
}

@AnnMarieW
Copy link
Collaborator Author

Could we do something like what you are doing with the persistence:

I don't think so - defaultProps is deprecated.

@BSd3v
Copy link
Collaborator

BSd3v commented Jul 25, 2025

Could we do something like what you are doing with the persistence:

I don't think so - defaultProps is deprecated.

Its a basic variable, doesnt go anywhere. 😏

@AnnMarieW
Copy link
Collaborator Author

@KoolADE85

Thanks for taking a look! I just wanted to do one more review and add some notes and a changelog:

  • This PR is compatible with the v32 branch, in case you’d like to do a patch release for 32. The only difference is the default value for className: in v33 it is set to '', and in v32 it is "ag-theme-alpine".

  • Props that were previously set to null or false have been removed, as it’s not necessary to set those as defaults.

  • For the remaining props not defined in the function parameter list, it was simpler to keep them within the props object and set fallbacks where needed, since props are used in several places throughout the code.

@AnnMarieW AnnMarieW marked this pull request as ready for review July 25, 2025 17:54
@AnnMarieW AnnMarieW marked this pull request as draft July 26, 2025 12:21
@AnnMarieW
Copy link
Collaborator Author

@KoolADE85

I was confused by the typo in the @BSd3v post above which shows defaultProps still being used in React 18, but his actual code uses a < rather than > and it works great.

if (
 parseFloat(React.version.substring(0, React.version.lastIndexOf('.'))) >
    REACT_VERSION_DASH2_COMPAT
) {
    DashAgGrid.defaultProps = defaultProps;

Passing the default props like how he suggested is a more elegant solution than what I have so far:

 <RealComponent parentState={state} {...defaultProps} {...props} />

Let's close my PR in favor of his when he does the PR.

@KoolADE85
Copy link
Contributor

@KoolADE85

I was confused by the typo in the @BSd3v post above which shows defaultProps still being used in React 18, but his actual code uses a < rather than > and it works great.

if (
 parseFloat(React.version.substring(0, React.version.lastIndexOf('.'))) >
    REACT_VERSION_DASH2_COMPAT
) {
    DashAgGrid.defaultProps = defaultProps;

Passing the default props like how he suggested is a more elegant solution than what I have so far:

 <RealComponent parentState={state} {...defaultProps} {...props} />

Let's close my PR in favor of his when he does the PR.

Sure, sounds good to me! I'll wait on that pr, then. Let me know if I can help push anything along @BSd3v, @AnnMarieW !

@AnnMarieW
Copy link
Collaborator Author

closed in favor of #392

@AnnMarieW AnnMarieW closed this Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove defaultProps

3 participants