-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Add possibility of null
in the return type of the useGridApiRef()
hook
#16353
Conversation
Deploy preview: https://deploy-preview-16353--material-ui-x.netlify.app/ Updated pages: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's messy, but the type is more accurate now 👍🏻
Thanks!
docs/data/migration/migration-data-grid-v7/migration-data-grid-v7.md
Outdated
Show resolved
Hide resolved
Signed-off-by: Armin Mehinovic <[email protected]>
126d26c
to
310365f
Compare
@arminmeh, for tests though, wouldn't it be better to have an internal implementation that is not null? I'd rather have a runtime error if I forgot to bind the |
@lauri865 that makes sense. For most of the test it will not matter, since the optional chaining affects certain action(s) that if silently fails will fail the test assertion |
I didn't mean that the change would break any old tests, but more a thought about writing new tests going forward. |
Well, you made me doubt it now 😅 I didn't spend to much time on the test updates as I tried to make the CI pass as fast as possible |
…idApiRef()` hook (mui#16353) Signed-off-by: Armin Mehinovic <[email protected]>
Closes #16000
Also related to #16279
since it is adding the v8 part of the types matrix
Changelog
Breaking changes
Return type of the
useGridApiRef()
hook and the type ofapiRef
prop are updated to explicitly include the possibilty ofnull
. In addition to this,useGridApiRef()
returns a reference that is initialized withnull
instead of{}
.Only the initial value and the type are updated. Logic that initializes the API and its availability remained the same, which means that if you could access API in a particular line of your code before, you are able to access it as well after this change.
Depending on the context in which the API is being used, you can decide what is the best way to deal with
null
value. Some options are:apiRef
is notnull
apiRef
isnull
apiRef
isnull