Open Janpot opened 2 months ago
@Janpot not sure if I am missing something here besides the console output, what is the expected handling for the state change?
Once the row is out of the draft, it is removed from rows
const rows = React.useMemo(
() => (draft ? [draft, ...rowsFromExternalApi] : rowsFromExternalApi),
[draft]
);
This is why row data cannot be fetched here and we end up with the error (in dev mode) and some missing data in the callback args
Having a separate rows
state like in the CRUD example that you have shared, solves the issue
https://stackblitz.com/edit/react-xqph3o-j4obgd?file=Demo.tsx
besides the console output, what is the expected handling for the state change?
null
for its second parameter. My expectation is that it never gets called with arguments that don't satisfy their types.processRowUpdate
gets called, I expect it to get passed the original row and the updated row. i.e. store the row values when edit starts and use that value when row edit stops instead of trying to read it from the grid state.Having a separate rows state like in the CRUD example that you have shared, solves the issue
IMO the example is too simplistic:
react-query
will potentially even invalidate and refetch them in the background while the create flow is active. The code in the example feels a bit anti-react to me as it requires careful curating of the rows
state instead of deriving it from "am I in row creation mode or not" state.Lets add this to the board for further discussion!
Steps to reproduce
Link to live example: https://stackblitz.com/edit/react-xqph3o?file=Demo.tsx
Steps:
Current behavior
it prints
The original row is lost, as well as the id in the updated row. Note that this
null
is also inconsistent with the type signature.Expected behavior
It should print
Alternatively one could argue the types should be updated, but that effectively results into a loss of information in the API. i.e. you lose the start value to compare with as well as the assigned id.
Context
Trying to build a more reliable version of the CRUD example I've ran into this several times.
Your environment
``` Don't forget to mention which browser you used. Output from `npx @mui/envinfo` goes here. ```npx @mui/envinfo
Search keywords: processRowUpdate null