Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3476: DataTable: TypeError when adding and starting editing a new row #3664

Merged
merged 1 commit into from
Nov 17, 2022
Merged

Conversation

yanxiyue
Copy link
Contributor

@yanxiyue yanxiyue commented Nov 17, 2022

#3476

  1. The cause seems to be that editingMeta was not initialized in this specific case.
  2. editingMeta will be updated by useUpdateEffect hook, when BodyCell's editingState changed.
  3. in this case, BodyCell is not mounted yet, so, the update logic will not be executed

Therefore,I try change useUpdateEffect to React.useEffect, it works well.

@github-actions
Copy link

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Nov 17, 2022
@melloware melloware linked an issue Nov 17, 2022 that may be closed by this pull request
@@ -463,14 +463,16 @@ export const BodyCell = React.memo((props) => {
}
}, [props.editingMeta]);

useUpdateEffect(() => {
/* eslint-disable */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not have to disable eslint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to disable that, but I couldn't build it successfully, I'm not very familiar with react, please tell me how to do better

$ npm run build:lib

> primereact@8.7.3-SNAPSHOT build:lib
> NODE_ENV=production INPUT_DIR=components/lib/ OUTPUT_DIR=dist/ npm run build:package


> primereact@8.7.3-SNAPSHOT build:package
> npm run build:check && rollup -c && gulp build-resources && npm run build:api


> primereact@8.7.3-SNAPSHOT build:check
> npm run lint && npm run format:check && npm run type:check && npm run security:check && (NODE_ENV=test npm run test:check)


> primereact@8.7.3-SNAPSHOT lint
> next lint --max-warnings=0


./components/lib/datatable/BodyCell.js
473:8  Warning: React Hook React.useEffect has missing dependencies: 'editingKey', 'getCellCallbackParams', and 'props'. Either include them or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the useEffect call and refer to those specific props inside React.useEffect.  react-hooks/exhaustive-deps

@melloware
Copy link
Member

@yanxiyue thanks for the fix can you also comment on the ticket so then I can assign it to you?

@melloware
Copy link
Member

@yanxiyue this should work...

    React.useEffect(() => {
        if (props.editMode === 'cell' || props.editMode === 'row') {
            const callbackParams = getCellCallbackParams();
            const params = { ...callbackParams, editing: editingState, editingKey };

            props.onEditingMetaChange(params);
        }
     // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [editingState]);

@yanxiyue
Copy link
Contributor Author

@yanxiyue this should work...

    React.useEffect(() => {
        if (props.editMode === 'cell' || props.editMode === 'row') {
            const callbackParams = getCellCallbackParams();
            const params = { ...callbackParams, editing: editingState, editingKey };

            props.onEditingMetaChange(params);
        }
     // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [editingState]);

got it. fixed.

@melloware melloware merged commit 477be8a into primefaces:master Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataTable: TypeError when adding and starting editing a new row
2 participants